由於項目需要,我僅有MDF和LDF文件,使用第三方工具進行導入數據庫。
1.采用windows連接
2.新建查詢:
EXEC sp_attach_db @dbname = '你的數據庫名',
@filename1 = 'mdf文件路徑(包綴名)',
@filename2 = 'Ldf文件路徑(包綴名)'
例如 :
EXEC sp_attach_db @dbname = 'Shop',
@filename1 = 'F:\Supermarket\Database\Shop.mdf',
@filename2 = 'F:\Supermarket\Database\Shop_log.LDF'
可能出現的錯誤:
“拒絕訪問”====》打開MDF或者LDF文件的屬性-》安全-》修改Authenticated Users-更改該組權限為完全控制權限,再次附加成功。如下圖:
3.再次進行導入,出現“Database ‘pubs’ cannot be upgraded because its non-release version (539) is not supported by this version of SQL Server.
You cannot open a database that is incompatible with this version of sqlservr.exe. You must re-create the database.
Could not open new database ‘pubs’. CREATE DATABASE is aborted. (Microsoft SQL Server, Error: 950)”
意思就是版本不兼容,參考外網的解決辦法:
通過導出到SQL腳本並在目標服務器上執行來提取源數據庫,或者使用SQL數據庫遷移向導。
希望能夠解決你的問題。