客户的一台现场采集电脑崩溃,无法启动。用PE引导后,将MDF和LDF数据复制出来,往正常的数据库附加时,报如下错误:

处理数据库 'databasename' 的日志时出错。如果可能,请从备份还原。如果没有可用备份,可能需要重新生成日志。无法打开新数据库 'databasename'。CREATE DATABASE 中止。 (Microsoft SQL Server,错误: 9004)


查找资料以后,凡是带有“update sysdatabases set status=-32768 where dbid=DB_ID('test')”这个语句的,一律无效,会报“不允许对系统目录进行即席更新。”,sql server2005以后不允许更新系统目录了。

以下方法经我测试有效:

解决步骤:
1.使用默认方式建立一个供恢复使用的数据库(如database_forrestore)。
2.停止数据库实例服务。
3.将刚才生成的数据库的日志文件database_forrestore.ldf删除,用要恢复的数据库mdf文件覆盖刚才生成的数据库数据文件database_forrestore_data.mdf。
4.启动数据库服务器。此时会看到数据库database_forrestore不可访问。
5. ALTER DATABASE database_forrestore SET EMERGENCY
6. ALTER DATABASE database_forrestore SET SINGLE_USER【这一步是为了执行下面的dbcc】
7. ALTER DATABASE database_forrestore REBUILD LOG ON (NAME=dbname_log, FILENAME='d:\data\database_forrestore_log.ldf')
    执行后,会有警告信息“警告: 数据库 'database_forrestore' 的日志已重新生成。已失去事务的一致性。RESTORE 链已断开,服务器不再有以前的日志文件的上下文,因此您需要了解它们的内容。应运行 DBCC CHECKDB 验证物理一致性。数据库已置于 dbo-only 模式。在准备使数据库可用时,需要重置数据库选项,并删除所有多余的日志文件。”
8. DBCC CHECKDB(<dbname>, REPAIR_ALLOW_DATA_LOSS) 【这一步时,我这里报655错误,版本不兼容,让我升级数据库,我的sqlserver服务器是2012,用sp_dbcmptlevel查看database_forrestore 其兼容级别是110,也是2012,应该不存在兼容问题,但是这一步就是执行不了,可以跳过】
9. ALTER DATABASE database_forrestore  SET MULTI_USER【恢复多用户模式】
10. ALTER DATABASE database_forrestore  SET ONLINE 【联机,可以在数据库上的右键菜单中执行】

11.刷新,至此,数据应该回来了

这里还有个英文版可以参考

ERROR : 9004 An error occurred while processing the log for database.
If possible, restore from backup.
If a backup is not available, it might be necessary to rebuild the log.

If you receive above error it means you are in great trouble. This error occurs when database is attempted to attach and it does not get attached. I have solved this error using following methods. Hope this will help anybody who is facing the same error.

Microsoft suggest there are two solution to this problem.

1) Restore from a backup.

  • Create Empty Database with same name and physical files (.ldf and .mdf).
  • Shut down SQL Server.
  • Replace the files which you want to attach with this new empty database files.
  • Start SQL Server.
  • Database will be in suspect mode which means so far everything going as it should be.
  • Next is to put database in emergency mode. ALTER DATABASE <DatabaseName> SET EMERGENCY will change the database status to emergency.
  • A database which is in emergency mode can be repaired with allowing some data loss. DBCC CHECKDB REPAIR_ALLOW_DATA_LOSS will do the task.
  • In this process some of the data may be lost but database will in working condition with most of the data retrieved from log.

2) Rebuild the log.

  • Create database using CREATE DATABASE FOR ATTACH_REBUILD_LOG.
  • This may fix the problem right away if database which is attempted to be attach is shut down properly. If database is corrupt it will be not restored correctly.
  • Next DBCC CHECKDB REPAIR_ALLOW_DATA_LOSS should be ran to bring back the database operational. This may loose some data but it may bring back database in working condition.
  • In this option as log is rebuilt SQL Server does not use log file to retrieve any data. In this process none of the log operation like transaction rollback will work.

I prefer to use the first method if it works. First method has worked sevral time without any issue. Syntax of the CREATE database can be found on Book Online for further guidance.

Reference : Pinal Dave (http://blog.SQLAuthority.com)

SQL Server的“错误:9004”的更多相关文章

  1. Microsoft SQL Server 数据库 错误号大全

    panchzh :Microsoft SQL Server 数据库 错误号大全0 操作成功完成. 1 功能错误. 2 系统找不到指定的文件. 3 系统找不到指定的路径. 4 系统无法打开文件. 5 拒 ...

  2. SQL Server出现错误: 4014

    SQL Server出现错误: 4014 线下的测试机器老是报错,从errorlog里看到大量的4014错误 A fatal error occurred , output error: ). 错误: ...

  3. SQL SERVER 9003错误解决方法 只适用于SQL2000

    SQLSERVER 9003错误解决方法 只适用于SQL2000 (只适用于SQL2000) "无法打开新数据库 'POS'.CREATE DATABASE 中止. (Microsoft S ...

  4. SQL SERVER错误:已超过了锁请求超时时段。 (Microsoft SQL Server,错误: 1222)

    在SSMS(Microsoft SQL Server Management Studio)里面,查看数据库对应的表的时候,会遇到"Lock Request time out period e ...

  5. Cannot set a credential for principal 'sa'. (Microsoft SQL Server,错误: 15535)

    在SQL SERVER 2008上上禁用sa登录时,遇到下面错误:"Cannot set a credential for principal 'sa'. (Microsoft SQL Se ...

  6. 无法打开物理文件xxx.mdf操作系统错误 5:“5(拒绝访问。)” (Microsoft SQL Server,错误: 5120)的解决方法

    无法打开物理文件xxx.mdf操作系统错误 5:“5(拒绝访问.)” (Microsoft SQL Server,错误: 5120)的解决方法   问题描述: 在附加数据库到sql server时,附 ...

  7. 无法删除服务器 'old_server_name',因为该服务器用作复制过程中的发布服务器。 (Microsoft SQL Server,错误: 20582)

    无法删除服务器 'old_server_name',因为该服务器用作复制过程中的发布服务器. (Microsoft SQL Server,错误: 20582) 2013-01-05 15:02 478 ...

  8. Sql Server 相关错误问题及解决方法

    1.首当其冲是登陆问题, SQL Server 2008选择Windows身份验证无法登录 (Microsoft Sql Server,错误:18456) 就是在连接SQL Server 2008时, ...

  9. SQL Server 2008 错误15023:当前数据库中已存在用户或角色

    解决SQL Server 2008 错误15023:当前数据库中已存在用户或角色,SQLServer2008,错误15023,在使用SQL Server 2008时,我们经常会遇到一个情况:需要把一台 ...

随机推荐

  1. 关于帧中继和ppp的补充笔记

    帧中继: · 两个设备都要启用 帧中继功能, 否则是不能 ping通的 · 两个设备上的接口serial要 no shutdown · · 一定要配置dlci地址(号). 否则就不能起来pvc 可以 ...

  2. 机器学习的5种语言(选自info world)

    摘要:机器学习目前炙手可热,本文搜集了Java.Python以及go等编程语言中常见且实用的开源机器学习工具,对机器学习感兴趣的开发者或者准备和机器学习打交道的数据科学家们不能错过了 [编者按] 机器 ...

  3. jQuery.validator 验证规则详解

    前言:jQuery.validator是一款非常不错的表单验证插件,验证方式非常简单方便,它还对HTML5做了兼容处理,了解了验证规则,就基本掌握了它的使用,下面就让我一一道来 jQuery.vali ...

  4. PHP CLI下接受参数的几种方法

    PHP CLI(命令行模式下)接受参数有多种方法: (1)使用$argv接受参数 <?php //变量仅在 register_argc_argv 打开时可用. print_r($argc); / ...

  5. [译]Exploring Angular 1.3: Binding to Directive Controllers

    原文: http://blog.thoughtram.io/angularjs/2015/01/02/exploring-angular-1.3-bindToController.html Angul ...

  6. 基于iSCSI的SQL Server 2012群集测试(三)--SQL Server 2012群集安装总结

    5.SQL Server 2012群集安装总结 5.1 群集与非群集的安装区别总结 SQL Server虚拟名称: 非群集环境下,本地服务器的名称就是SQL Server服务器名称:但在群集环境下,由 ...

  7. 牡丹江.2014B(图论,树的直径)

    B - Building Fire Stations Time Limit:5000MS     Memory Limit:131072KB     64bit IO Format:%lld & ...

  8. C# switch

    要开学了(啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊) 做个沉默的行动者吧!(嘘嘘嘘嘘嘘嘘)今天去水题发现好多基础都不知道啊 1.   switch(控制语句) { case 常量表达式:{statement ...

  9. nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器[转]

    转 :http://redstarofsleep.iteye.com/blog/2123752 Nginx本身是一个非常出色的HTTP服务器,FFMPEG是非常好的音视频解决方案.这两个东西通过一个n ...

  10. 38 网络相关函数(六)——live555源码阅读(四)网络

    38 网络相关函数(六)——live555源码阅读(四)网络 38 网络相关函数(六)——live555源码阅读(四)网络 简介 12)makeSocketNonBlocking和makeSocket ...