问题
I have a website deployed in a server. One day it threw an error saying the connection string
name is already added. I checked the web.config file and it has only one entry in that name. I removed the entry from the config. Now the website worked well and fetched data from database.
Note: When I changed the name of the config file it show error.
I think, the issue is – the connectionstring part is cached in memory. Is it so? How can we overcome this unwanted behavior?
Config Files in Source Code
Release Config
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
Debug Config
<system.web>
</system.web>
REFERENCES:
- Issue with unwanted connection string appearing in my published web config
- .NET 2.0 App.Config connection strings includes unwanted SQLExpress default
回答1:
That is not the issue - when you change the web.config
file, the IIS process gets reset, so there can't be any caching involved.
What is more probable is that there is either a parent or child directory with a web.config
file that contains the same connection string name - this is causing the error.
You can solve that in several ways:
- Ensure there is only one
web.config
in the correct scope with the connection string name Use the
remove
element:<connectionStrings> <remove name="theConnectionString" /> <add name="theConnectionString" ... /> <connectionStrings>
Refer Encrypted config file does not apply “remove” tag in connectionStrings for a related question
来源:https://stackoverflow.com/questions/14258406/duplicate-connection-string-error