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.)
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.