The entry has already been added

32,969

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.

Share:
32,969

Related videos on Youtube

Jorge
Author by

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, 2020

Comments

  • Jorge
    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=&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.)

    • Prashant Lakhlani
      Prashant Lakhlani about 10 years
      try adding <Clear\> before first element in connectionStrings element
    • Prashant Lakhlani
      Prashant Lakhlani about 10 years
      It looks like <Clear/> and <Remove name="DefaultConnection"/> both before all add should do the trick.
    • Jorge
      Jorge about 10 years
      Doesn't work it does not find any connection string in my web.config
    • Mohamad Mahmoud Darwish
      Mohamad Mahmoud Darwish over 6 years
  • Jorge
    Jorge about 10 years
    Sorryy but first I don't have declare any providers and already tried the clear but it doesn't work
  • Neel
    Neel about 10 years
    ok 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
    Jorge about 10 years
    Checked too but no, it does not have a connection with the same name
  • Neel
    Neel about 10 years
    I would suggest you rename DefaultConnection to something else like MyAppServices @Jorge
  • Eon
    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 bogus web.config. This fix did wonders for my local environment
  • Tim
    Tim almost 8 years
    Just changing the name to MyAppServices worked for me - but now I have a 404 error :-(