The entry '' has already been added error

不想你离开。 提交于 2019-12-17 10:32:26

问题


I have a web.config in ASP.net giving me configuration error.

 <connectionStrings>   
<add name="conn1" connectionString="Data Source=test;database=test;uid=test;pwd=test"/>
<add name="conn2" connectionString="Data Source=123.123.1.123;database=test2;uid=test;pwd=test"/>
...

It throws "The entry 'conn2' has already been added." error. I know I only added it once. Not sure what it is wrong with.


回答1:


it can be in web.config that is parent to this one. just add

<remove name="conn2" />

before your add it (again) :)

alternatively clear all connection string using

<clear />



回答2:


You should use <clear /> when adding any providers to your web.config. Read this article: http://weblogs.asp.net/scottgu/archive/2006/11/20/common-gotcha-don-t-forget-to-clear-when-adding-providers.aspx

The root cause of the above problem rests in how the new provider was registered within the web.config file.

The section within the web.config file is implemented as a collection, and so it is possible to register multiple providers at the same time

If you have another project using the same connection string name you will receive this error because that connection string has already been added to the collection.




回答3:


If you override the ToString() method then this will work. Looks like the configuration mechanism uses that to check if something already exists in the collection



来源:https://stackoverflow.com/questions/6679233/the-entry-has-already-been-added-error

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