2016-07-31 111 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