The entry has already been added
After the <providers>
and before the first <add....>
node, add a <clear />
node. That will fix it!!
Or it can be in web.config that is parent to this one. Just add the below code before you add it again.
<remove name="DefaultConnection" />
Alternatively, clear all connection strings using
<clear />
I would suggest you rename DefaultConnection to something else like MyAppServices.
Related videos on Youtube
![Jorge](https://i.stack.imgur.com/soily.jpg?s=256&g=1)
Jorge
I'm a software developer with knowledge in C# javascript, Jquery .Net asp.net-mvc, web-api node.js Always interested in agile methodologies. My StackOverflow CV twitter
Updated on August 21, 2020Comments
-
Jorge almost 4 years
All my Razors views have this error:
The pre-application start initialization method Start on type WebMatrix.WebData.PreApplicationStartCode threw an exception with the following error message:
The entry 'DefaultConnection' has already been added.
Now, as you can see in my connection string configuration, I don't have the connection string name repeated:
<connectionStrings> <add name="DefaultConnection" connectionString="Data Source=.\foo;Initial Catalog=aspnet-foo-20130212133051;MultipleActiveResultSets=true;Integrated Security=SSPI" providerName="System.Data.SqlClient" /> <add name="ServiDeskConnection" connectionString="Data Source=fooo;Initial Catalog=mdb;User Id=foo;Password=fooo;MultipleActiveResultSets=true" providerName="System.Data.SqlClient" /> <add name="mdbEntities" connectionString="metadata=res://*/Models.ExternalData.ExternalContext.csdl|res://*/Models.ExternalData.ExternalContext.ssdl|res://*/Models.ExternalData.ExternalContext.msl;provider=System.Data.SqlClient;provider connection string="data source=foo;initial catalog=mdb;user id=foo;password=foo_prod01;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> <add name="SisInfoInventoryEntities" connectionString="metadata=res://*/Models.ExternalData.Inventory.csdl|res://*/Models.ExternalData.Inventory.ssdl|res://*/Models.ExternalData.Inventory.msl;provider=System.Data.SqlClient;provider connection string="data source=.\foo;initial catalog=foo;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> </connectionStrings>
I already tried to use
<Clear/>
, but it is worse, because it said that I don't have any connection.I tried to unload the project of the same solution, but it stills did not work.
Note that when I build the project, it works well.
(This has been answered several times, but none of the solutions had worked for me.)
-
Prashant Lakhlani about 10 yearstry adding
<Clear\>
before first element in connectionStrings element -
Prashant Lakhlani about 10 yearsIt looks like
<Clear/>
and<Remove name="DefaultConnection"/>
both before alladd
should do the trick. -
Jorge about 10 yearsDoesn't work it does not find any connection string in my web.config
-
Mohamad Mahmoud Darwish over 6 yearsPossible duplicate of The entry '' has already been added error
-
-
Jorge about 10 yearsSorryy but first I don't have declare any providers and already tried the clear but it doesn't work
-
Neel about 10 yearsok and Also worth checking that you do not have the Connection String added at a higher level, e.g. the MACHINE.CONFIG file. @Jorge
-
Jorge about 10 yearsChecked too but no, it does not have a connection with the same name
-
Neel about 10 yearsI would suggest you rename DefaultConnection to something else like MyAppServices @Jorge
-
Eon almost 9 years
<clear/>
dirty and naughty little fix that - especially if multiple developers work on the same file and end up breaking your environment every time they check in some bogusweb.config
. This fix did wonders for my local environment -
Tim almost 8 yearsJust changing the name to MyAppServices worked for me - but now I have a 404 error :-(