我最初是我的應用程序的數據模型的代碼第一次使用EF6和的LocalDB所有已工作的罰款。代碼首先EF在本地數據庫 - 移動到企業的SQL Server
我現在需要到數據庫移動到我們企業的SQL Server環境,但我沒有相應的權限,以便能夠使用代碼第一次......所有的腳本來創建/修改都將產生,評估,審批,由數據庫管理員執行..
我的問題是,我有作爲的人我已經嘗試都失敗了與我的數據庫連接字符串的問題。如前所述,在使用LocalDB之前,使用了默認的連接字符串。
的DbContext構造
public HotelRequestDBContext() : base("HotelRequestsDB")
{
//Database.SetInitializer<HotelRequestDBContext>(new HotelRequestDBContextInitialiser());
if (Properties.Settings.Default.EFTrace)
{
this.Database.Log = msg => System.Diagnostics.Trace.WriteLine(msg);
}
}
連接字符串嘗試1
<add name="HotelRequestsDB" connectionString="Data Source=server\instance;initial catalog=HoteRequests;persist security info=True;user id=username;password=password;multipleactiveresultsets=True;application name=EntityFramework" providerName="System.Data.EntityClient" />
Exception thrown: 'System.ArgumentException' in EntityFramework.dll
Additional information: Keyword not supported: 'data source'.
If there is a handler for this exception, the program may be safely continued.
連接字符串嘗試2
<add name="HoteRequestsDB" connectionString="metadata=res://*/HoteRequests.csdl|res://*/HoteRequests.ssdl|res://*/HoteRequests.msl;provider=System.Data.SqlClient;provider connection string="data source=server\instance;initial catalog=HoteRequests;persist security info=True;user id=user;password=password;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />
異常彈出窗口
Exception thrown: 'System.Data.DataException' in EntityFramework.dll
Additional information: An exception occurred while initializing the database. See the InnerException for details.
If there is a handler for this exception, the program may be safely continued.
調試輸出窗口
Cannot attach the file 'C:\Projects\HotelRequests\HotelRequests\App_Data\HotelRequestsDB.mdf' as database 'HotelRequestsDB'.
什麼是您的錯誤信息? – strickt01
更新了問題 –
只是要清楚,數據庫已經在sql服務器上了嗎?如你所說,你不能使用代碼首先自己創建它們 –