I have a web server with multiple application running. All the application have their web.config
file. If the database password changes due to Policy I have to manually change the password in each of web.config
files in the app setting section.
I was reading about the connection string setting in machine.config
file.
Now my question is if I put connection string in appsetting section of machine.config
with name ConnectionString
and same in my web.config
file will it overwrite the machine.config
file values.
In my machine.config
following is the setting
<configuration>
....
<appSettings>
<add key="ConnectionString" value="value"/>
</appSettings>
</configuration>
similarly in my web.config
file
<configuration>
....
<appSettings>
<add key="ConnectionString" value="value"/>
</appSettings>
</configuration>
And I get the value in my code as below
string conString=ConfigurationManager.AppSettings["ConnectionString"];
will I get the overloaded value?
What's going to help you out here is to store your connection string(s) in .config file and then reference them either using the
file=""
attribute or theconfigSource=""
attribute.Here's an excellent question and answer that talks about the differences between the two and shows you how to implement them:
ASP.NET web.config: configSource vs. file attributes