Recently, we were facing this error while deploying the asp.net solution into server (IIS) as a separate application (Sub Domain) in a main web application.

Scenario

I created a website ( say site mymainsite ) in window server IIS under a port and then added an another application ( plugin ) under a root-site ( mymainsite ) as shown:

After deploying the solution, when I opened the site, I got this error. OOps!!!

“The entry ‘DefaultConnection’ has already been added. (C:..\web.config line ..)”

With some research, I found that it was conflicting with the parent site connection provider. There was a same connection name (DefaultConection) in the parent site.

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.

Solutions

Method 1:

We can fix this by updating the web.config file.

<remove name="DefaultConnection" />

Add above tag with connection string name just above the connection key.

Method 2:

Alternatively, you can clear all connection string adding below tag.

<clear />

Cheers!!

By Rijwan Ansari

Research and Technology Lead | Software Architect | Full Stack .NET Expert | Tech Blogger | Community Speaker | Trainer | YouTuber. Follow me @ https://rijsat.com Md Rijwan Ansari is a high performing and technology consultant with 10 plus years of Software Development and Business Applications implementation using .NET Technologies, SharePoint, Power Platform, Data, AI, Azure and cognitive services. He is also a Microsoft Certified Trainer, C# Corner MVP, Microsoft Certified Data Analyst Associate, Microsoft Certified Azure Data Scientist Associate, CSM, CSPO, MCTS, MCP, with 15+ Microsoft Certifications. He is a research and technology lead in Tech One Global as well as leading Facebook community Cloud Experts Group and SharePoint User Group Nepal. He is a active contributor and speaker in c-sharpcorner.com community, C# Corner MVP and his rank at 20 among 3+ millions members. Additionally, he is knee to learn new technologies, write articles, love to contribute to the open-source community. Visit his blog RIJSAT.COM for extensive articles, courses, news, videos and issues resolution specially for developer and data engineer.

2 thoughts on “ASP.NET Error: The entry ‘DefaultConnection’ has already been added. (C:\..\web.config line ..)”
  1. Howdy I am so grateful I found your blog, I really found you by error, while I was looking on Google for something else, Anyways I am here now and would just like to say kudos for a marvelous post and a all round thrilling blog (I also love the theme/design), I don抰 have time to go through it all at the minute but I have bookmarked it and also included your RSS feeds, so when I have time I will be back to read a great deal more, Please do keep up the superb work.

Leave a Reply

Your email address will not be published. Required fields are marked *