I want to declare my connection string in IIS and get it from there. I don't want to declare it in web.config page. Rather I need to know if is it possible to get the string from iis in web.config or read it from code file. I am using asp.net 4.0.,coding in c# and server is IIS7.5
According to this article you can use the IIS UI, or the command line to modify your connection string, but this will just write into the <connectionString>
element in the web.config file any way (unless you've set it up to save elsewhere).
Also, you can store it in another .config file if you wish, and pull it into your web.config like so
<appSettings file="../VirtualDirectory/config/Env.config">
</appSettings>
You could then call it like so in your code:
System.Configuration.ConfigurationManager.AppSettings["DefaultConn"]
This can be quite useful if you want the location of your connection string to not be under your site (i.e. in a virtual directory).
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