ace333 Posted August 11, 2005 Posted August 11, 2005 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> Quote
Administrators PlausiblyDamp Posted August 11, 2005 Administrators Posted August 11, 2005 something like settings = new AppSettingsReader(); string connString = (string) settings.GetValue("ConnectionString", typeof(string)); Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Experts* Bucky Posted August 11, 2005 *Experts* Posted August 11, 2005 There's more than one way to skin a cat! string connString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"] Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.