3

I was getting an error saying that one of my connection string in my application's web.config file was already defined.

I checked in the IIS settings and when I checked the connection string property it was there already with Entry Type : Inherited.

So I went up the chain and went all the way up to the root of the localhost and checked the connection strings there.

I found a bunch of connection strings there as well.. but they're also all with Entry Type Inherited..

I checked the web.config file inside the wwwroot folder but didn't find any connection strings defined in there..

Where could these connection strings be coming from?...

enter image description here

psj01
  • 3,075
  • 6
  • 32
  • 63
  • Did you check the machine.config file? https://stackoverflow.com/questions/2325473/where-is-machine-config – JuanR Oct 03 '17 at 13:58

1 Answers1

5

Configuration files in .NET are inherited in the following order:

  • systemroot\Microsoft .NET\Framework\versionNumber\CONFIG\Machine.config
  • systemroot\Microsoft .NET\Framework\versionNumber\CONFIG\Web.config (ASP.NET only)
  • (application directory)\Web.config

So the connection strings that show up as "inherited" are specified in either of the upper two files.

Reference: MSDN: ASP.NET Configuration File Hierarchy and Inheritance

If you don't want to alter the machine-wide configuration, you can <clear /> them from being inherited in your application's configuration as explained in What does <clear /> signify when specifying a connectionstring?:

<connectionStrings>
   <clear />
   <add name="LocalSqlServer" connectionString="..." /> 
</connectionStrings>
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Thank you. I was able to find them inside C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config – psj01 Oct 03 '17 at 14:16