Duplicate Connection String Error

瘦欲@ 提交于 2019-12-08 08:08:01

问题


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:

  1. Issue with unwanted connection string appearing in my published web config
  2. .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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!