跳到主要內容

The database could not be exclusively locked to perform the operation

這個問題是, 當我用SSMS更改資料庫的名稱時, 結果遇到以下的錯誤訊息,

The database could not be exclusively locked to perform the operation.

原因是目前尚有其他connection正在連接資料庫, 所以我們的請求被拒絕了
解決的方法很簡單, 宣告單人模式(single user)來搶資源
ALTER DATABASE [C:\APS\APP_DATA\BOTDATA.MDF] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE [C:\APS\APP_DATA\BOTDATA.MDF] SET SINGLE_USER;
--Do something

ALTER DATABASE [BotData] SET MULTI_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE [BotData] SET MULTI_USER;



留言