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?

1
  • Yes the value in Web.Config will override the value present in your Machine.Config file. Commented Jan 21, 2016 at 6:11

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.