In my code behind page, how do I access the connection string which is stored in my web.config file?
System.Web.Configuration.WebConfigurationManager.ConnectionStrings["YouConnStringName"].ConnectionString;
This requires references to System.Configuration.dll and System.Web.dll.
How to: Read Connection Strings from the Web.config File
From comment on http://msdn.microsoft.com/en-us/library/ms178411.aspx
string c = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["myconnectionstringname"].ConnectionString;
Requires your project to reference to System.Web and System.Configuration. I had to actually add a reference to "System.Configuration" not just add a Using.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With