The entry has already been added
Asked Answered
V

1

21

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=&quot;data source=foo;initial catalog=mdb;user id=foo;password=foo_prod01;multipleactiveresultsets=True;App=EntityFramework&quot;" 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=&quot;data source=.\foo;initial catalog=foo;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" 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.)

Virgina answered 1/4, 2014 at 4:48 Comment(4)
try adding <Clear\> before first element in connectionStrings elementCucurbit
It looks like <Clear/> and <Remove name="DefaultConnection"/> both before all add should do the trick.Cucurbit
Doesn't work it does not find any connection string in my web.configVirgina
Possible duplicate of The entry '' has already been added errorLoon
S
55

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.

Shayneshays answered 1/4, 2014 at 4:53 Comment(6)
Sorryy but first I don't have declare any providers and already tried the clear but it doesn't workVirgina
ok and Also worth checking that you do not have the Connection String added at a higher level, e.g. the MACHINE.CONFIG file. @VirginaShayneshays
Checked too but no, it does not have a connection with the same nameVirgina
I would suggest you rename DefaultConnection to something else like MyAppServices @VirginaShayneshays
<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 bogus web.config. This fix did wonders for my local environmentSmattering
Just changing the name to MyAppServices worked for me - but now I have a 404 error :-(Johnathan

© 2022 - 2024 — McMap. All rights reserved.