我有一個應用程序可以正常工作,與實體框架和C#和SQL Server。在它的模型層我有App.Config中我有連接字符串更改連接字符串上的服務器的名稱
<add name="Context1" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=server1;initial catalog=DB1;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
我tarnsfered數據庫到另一臺服務器,所以我改變了
Server1 to .\sqlExpress
或
Server1 to PCNAME\sqlExpress
它成爲的東西像這樣
<add name="Context1" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.\sqlExpress;initial catalog=DB1;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
最後,我構建了項目和解決方案。該應用程序不適用於新的dbserver。它給出了以下錯誤
Connection = 'context.Database.Connection' threw an exception of type 'System.InvalidOperationException'
base {System.SystemException} = {"No connection string named 'Context1' could be found in the application config file."}
哪個Context1存在,我只是改變了它的服務器名稱。 我能爲它做些什麼?
謝謝
添加完整的Web配置只是掩蓋了私人數據。很難這樣猜測 – Sherlock
在這裏找到類似的問題:http://stackoverflow.com/questions/12622408/no-connection-string-named-myentities-could-be-found-in-the-application-config。確保您已在您的解決方案上設置了正確的啓動項目,並在\ SQLEXPRESS之前提供您的機器名稱。 –
@TetsuyaYamamoto:通過更改。\ sqlExpress到Server1,再次一切正常,但與。\ sqlExpress它不會工作,所以啓動項目是好的 – nnmmss