The entry ” has already been added error

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

<add name="conn1" connectionString="Data Source=test;database=test;uid=test;pwd=test"/>
<add name="conn2" connectionString="Data Source=;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.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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 />

Method 2

You should use <clear /> when adding any providers to your web.config. Read this article:

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.

Method 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

Method 4

I got this error and the issue turned out to be a web.config deployed to the root of the domain

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x