2014-04-01 32 views
15

我所有的剃鬚刀的觀點有此錯誤:入口已經添加

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.

現在,你可以在我的連接字符串的配置看,我沒有重複的連接字符串名稱:

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

我已經試過使用<Clear/>,但它更糟,因爲它說我沒有任何連接。

我試圖卸載相同解決方案的項目,但它仍然沒有工作。

請注意,當我構建項目時,它運行良好。

(這已經回答了好幾次,但沒有一個解決方案,爲我工作過。)

+5

嘗試加入''前的ConnectionStrings元素 –

+0

嗨第一個元素,並感謝要求,已經嘗試過,但它不工作 – Jorge

+0

看起來既''以前'和'所有的'add'都應該這樣做。 –

回答

36

<providers>後和第一<add....>節點之前,添加一個節點<clear />。這將解決它!

或者它可以在web.config中,這是父親的。再次添加之前,請添加下面的代碼。

<remove name="DefaultConnection" /> 

另外,明確使用

<clear /> 

所有連接字符串,我建議你重新命名DefaultConnection到別的東西像MyAppServices。

+1

對不起,但首先我沒有聲明任何提供商,並已嘗試明確,但它不起作用 – Jorge

+0

好吧,也值得檢查,你沒有連接字符串添加在更高級別,例如MACHINE.CONFIG文件。 @Jorge – Neel

+0

也檢查了,但沒有,它沒有與同名的連接 – Jorge