Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading values from web.config

Status
Not open for further replies.

ace333

Programmer
Jul 12, 2005
105
CH
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>
 
Here's how we are reading it in vb:

Private _ConnectionString as String = GetApplicationSettings("ConnectionString")
 
try:
ConfigurationSettings.AppSettings("ConnectionString")

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top