上篇文章里, 我們通過腳本修改了數據庫MDF和LDF文件的位置, 恢復了之后, 發現數據庫處於Recovery Pending狀態.
如何解決呢?
嘗試一
=======================
運行下面的命令, 失敗.
RESTORE DATABASE SharePoint_Config WITH RECOVERY
報錯:
Msg 3148, Level 16, State 3, Line 1
This RESTORE statement is invalid in the current context. The 'Recover Data Only' option is only defined for secondary filegroups when the database is in an online state. When the database is in an offline state filegroups cannot be specified.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
嘗試二
======================
運行下面的命令, 失敗.
DBCC checkdb ('SharePoint_Config')
報錯:
Msg 945, Level 14, State 2, Line 1
Database 'SharePoint_Config' cannot be opened due to inaccessible files or insufficient memory or disk space. See the SQL Server errorlog for details.
這里注意到"inaccessible files"字樣, 於是想起應該檢查一下存放MDF和LDF的路徑的權限設置是否與默認的文件夾相同.
經過比較, 發現少了用戶"MSSQLSERVER"的full control.
添加NT Service\MSSQLSERVER用戶后, 賦予full control權限, 問題依舊. 看起來不是權限的問題.
筆者還嘗試了下面的命令, 均告失敗.
EXEC sp_resetstatus 'SharePoint_Config'; ALTER DATABASE "SharePoint_Config" SET EMERGENCY DBCC checkdb('SharePoint_Config') ALTER DATABASE "SharePoint_Config" SET SINGLE_USER WITH ROLLBACK IMMEDIATE DBCC CheckDB ('SharePoint_Config', REPAIR_FAST) DBCC CheckDB ('SharePoint_Config', REPAIR_ALLOW_DATA_LOSS)
筆者最后將兩個數據庫刪掉, 重新Attach MDF和LDF文件, 才將數據庫狀態恢復.
筆者不會放過這個問題, 明天找數據庫專家咨詢一下.
參考資料
=======================
Database States
http://msdn.microsoft.com/en-us/library/ms190442.aspx
DBCC CHECKDB
http://msdn.microsoft.com/en-us/library/aa258278%28v=sql.80%29.aspx
Suspect Database Recovery (SQL Server 2005)