2016-07-31 38 views
1

提取數據我有,我需要從中提取數據損壞的數據庫的問題..問題,同時從損壞的數據庫

爲啓動我們的數據庫服務器崩潰了,我們提取的.mdf和.ldf文件從文件系統,但它似乎是一個特定的數據庫「XYZ」是運行一些操作當事故發生時,我試圖連接我得到了下面的錯誤爲:

The log scan number (218:387:1) passed to log scan in database ‘XYZ’ is not valid

所以我幫閒通過創建一個連接它同名的數據庫,並替換.mdf文件並在停止SQL SERVER服務以重現您的情節後刪除新的.ldf o,並重新開始。

我也跟着從這個Link保羅·蘭德爾說明如下:

ALTER DATABASE [XYZ] SET EMERGENCY; 
GO 

ALTER DATABASE [XYZ] SET SINGLE_USER; 
GO 

DBCC CHECKDB (N’XYZ’, REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS, NO_INFOMSGS; 
GO 

,但是當我跑的DBCC CHECKDB命令我面臨以下消息

File activation failure. The physical file name 「E:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\XYZ_log.ldf」 may be incorrect. The log cannot be rebuilt because there were open transactions/users when the database was shutdown, no checkpoint occurred to the database, or the database was read-only. This error could occur if the transaction log file was manually deleted or lost due to a hardware or environment failure. Msg 5123, Level 16, State 1, Line 1 CREATE FILE encountered operating system error 3(failed to retrieve text for this error. Reason: 15105) while attempting to open or create the physical file ‘C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\XYZ_log.ldf’. Msg 5024, Level 16, State 2, Line 1 No entry found for the primary log file in sysfiles1. Could not rebuild the log. Msg 5028, Level 16, State 2, Line 1 The system could not activate enough of the database to rebuild the log. File activation failure. The physical file name 「E:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\XYZ_log.ldf」 may be incorrect. The log cannot be rebuilt because there were open transactions/users when the database was shutdown, no checkpoint occurred to the database, or the database was read-only. This error could occur if the transaction log file was manually deleted or lost due to a hardware or environment failure. Msg 5123, Level 16, State 1, Line 1 CREATE FILE encountered operating system error 3(failed to retrieve text for this error. Reason: 15105) while attempting to open or create the physical file ‘C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\XYZ_log.ldf’. Msg 5024, Level 16, State 2, Line 1 No entry found for the primary log file in sysfiles1. Could not rebuild the log. Msg 5028, Level 16, State 2, Line 1 The system could not activate enough of the database to rebuild the log. Msg 7909, Level 20, State 1, Line 1 The emergency-mode repair failed.You must restore from backup.

所以作爲最後的手段,我試圖在一個新的數據庫中自己SELECT INTO到每個表中,它對80%的表工作,但當涉及到一個特定的表「最重要的」當我試着SELECT INTO語句我遇到以下錯誤:

Could not continue scan with NOLOCK due to data movement.

是有任何解決方案,我得到一個提示,閱讀本身的每一頁,但我無法找到如何才能做到這一點。

我使用SQL Server 2008 R2的提前BTW

謝謝你,當你從損壞的表

我能瑞普選擇

+0

這聽起來更適合DBA站點,但爲什麼使用NOLOCK? –

+0

其實我沒有使用NOLOCK,完整的陳述是鍵入SELECT * INTO [新數據庫] .dbo。[表名] FROM [舊錶名] –

+0

對不起,我錯誤地發佈沒有完成我的評論,我只是編輯它 –

回答

0

Could not continue scan with NOLOCK due to data movement.

,也會出現此錯誤的整個問題,但我沒有複製日誌文件,因爲您可能會導致您的DBCC故障

爲避免DBCC故障,請嘗試此步驟..
1.Dont創建日誌文件
2.Just在相同的路徑創建具有相同名稱的數據庫,並複製MDF文件

然後運行下面的查詢..

alter database yourdb set emergency; 
go 

alter database yourdb set single_user; 
go 

現在運行DBCC CHECKDB,這將糾正錯誤,也可能從你的重要表

DBCC CHECKDB (N'yourdb', REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS, NO_INFOMSGS; 
GO 

這將成功完成刪除數據..

現在運行以下語句..

alter database yourdb set online 
go 

alter database yourdb set multi_user 
go