2016-06-09 253 views
1

如何使用2012年使用SQL Server創建的數據庫文件(.mdf)從Visual Studio調用它(作爲實例)?如何將SQL Server 2012 .mdf文件升級到SQL Server 2014?

SqlConnection con = new SqlConnection("Data Source = .\\SQLEXPRESS; Initial Catalog = DB; Integrated Security = False; User ID = hi; Password=123"); 

這是代碼來調用它,但僅適用於SQL Server 2012的如何在SQL Server 2014使用它呢?我一直在得到這個錯誤:

This database file is not compatible with the current instance of SQL Server.

To resolve this issue, you must upgrade the database file by creating a new data connection, or you must modify the existing connection to this database file.

+3

數據庫不是*文件*。你不能只從一臺服務器上獲取'mdf'文件並在另一臺服務器上打開它。從舊服務器上分離數據庫並將其附加到新服務器上。分離可確保在數據庫脫機之前完成所有現有事務。附加照顧任何必要的升級步驟。 –

+0

@PanagiotisKanavos我已經把它放到了我的sql server managament 2014中,它讀取它,現在我唯一的問題是我將如何在Visual Studio中調用它?它的恰當實例是什麼? –

+1

在您的sql server 2014實例中,運行以下腳本:CREATE DATABASE DB ON (FILENAME ='PATH_TO_YOUR_MDF_FILE') FOR ATTACH' – Hackerman

回答

1

晚了派對,但我發現了這一點。 升級不是自動的。關鍵是要觸發它。去

`Data Connections -> Default Connection -> Right Click -> Modify connection -> Advanced -> Data Source` 

然後應該有一個預先填充的下拉列表包含您的實例。

ok -> ok 

然後你會得到這個屏幕。 enter image description here

Default Connection Right Click -> refresh 

你的數據庫是enter image description here MDF中升級。

相關問題