c 還原資料庫

2021-06-29 13:01:51 字數 637 閱讀 3116

在還原乙個200m左右的bak格式資料庫檔案時遇到了兩個問題:

問題1:

restore 無法處理資料庫 '***x',因為它正由此會話使用。建議在執行此操作時使用 master 資料庫

問題2:

超時時間已到。在操作完成之前超時時間已過或伺服器未響應

解決及實現**如下:

string pathfile ;//bak檔案路徑

string dbname ;//資料庫名稱

string connectionstring;//資料庫連線字串

// 還原資料庫

if (!file.exists(pathfile)) return false;

sqlconnection conn = new sqlconnection(connectionstring);

string cmdstr = string.format("use master restore database from disk=''", dbname, pathfile);//新增「use master 」解決問題一

sqlcommand cmd = new sqlcommand(cmdstr, conn);

trycatch(exception ex)

finally

c 還原資料庫

string path this.fileupload1.postedfile.filename string dbname this.dropdownlist1.selectedvalue string sqlstr1 server local database this.dropdownlist...

還原資料庫

use gyjlbigfootmis goif exists select from sysobjects where name kymp 還原資料庫 and type p begin drop procedure kymp 還原資料庫 endgo create procedure kymp 還原資...

資料庫還原

訊息 5133,級別 16,狀態 1,第 1 行 對檔案 d microsoft sqlserver mssql.1 mssql data db camp unit 2.mdf 的目錄查詢失敗,出現作業系統錯誤 3 系統找不到指定的路徑。訊息 3156,級別 16,狀態 3,第 1 行 檔案 db ...