Reading from a web.config file

ace333

Newcomer
Joined
Jul 19, 2005
Messages
22
I have this web.config file and I have added a key value describing the connecting string to a db. I'm wondering whats the easiest way to read the value of the connection string from the web.config file, c# is the language i'm using.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!-- define the custom sections used below - do not change -->
<appSettings>

<add key="ConnectionString" value="DATA SOURCE=DLNOTC02;User Id=snare;Password=snare"/>

</appSettings>

<system.web>
<customErrors mode="Off" />
<compilation defaultLanguage="c#" debug="true"/>
<!--<customErrors mode="Off" defaultRedirect="aspx/GlobalError.aspx" />-->
<authentication mode="Windows"/>
<trace enabled="false" requestLimit="10" pageOutput="false" traceMode="SortByTime" localOnly="true"/>
<sessionState mode="Off"/>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" culture="en-GB"/>

<webServices>
<protocols>
<add name="HttpSoap"/>
<add name="HttpPost"/>
<add name="HttpGet"/>
<add name="Documentation"/>
</protocols>
</webServices>


</system.web>
</configuration>
 
There's more than one way to skin a cat!
Code:
string connString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]
 
Back
Top