1

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?

Community
  • 1
  • 1
शेखर
  • 17,412
  • 13
  • 61
  • 117

1 Answers1

1

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 the configSource="" 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

Community
  • 1
  • 1
Jerreck
  • 2,930
  • 3
  • 24
  • 42
  • the problem with the file is it overrides the `web.config` value but I want the reverse. So can do this in the link which you have provided? – शेखर Jan 21 '16 at 09:04