SQL Server 2005数据库日志文件损坏的情况下如何恢复数据库
在某些偶然的情况下,会引起SQL Server 2005数据库日志文件的损坏,比如:硬件故障、计算机非正常重启或关机。
当SQL Server 2005数据库日志文件损坏时,可能会出现以下情况:
1、在SQL Server Management Studio中显示数据库处于置疑(suspect)状态。
2、事件日志可能会出现如下错误信息:
Could not redo log record (21737:686:9), for transaction ID (0:2334886), on page (1:37527), database 'Test' (database ID 15). Page: LSN = (21735:299:5), type = 2. Log: OpCode = 3, context 19, PrevPageLSN: (21737:615:1). Restore from a backup of the database, or repair the database.
During redoing of a logged operation in database 'Test', an error occurred at log record ID (76116:286:2). Typically, the specific failure is previously logged as an error in the Windows Event Log service. Restore the database from a full backup, or repair the database.
3、无法分离数据库
4、用CREATE DATABASE DBName ON ( FILENAME = N'DBFile' ) FOR ATTACH_REBUILD_LOG附加数据库时出现提示:The log cannot be rebuilt because the database was not cleanly shut down.
恢复方法:
1、停止数据库服务。
2、将需要恢复的数据库文件复制到另外的位置。
3、启动数据库服务。
4、确认要恢复的数据库文件已经成功复制到另外的位置,然后在SQL Server Management Studio中删除要恢复的数据库。
5、新建同名的数据库(数据库文件名也要相同)。
6、停止数据库服务。
7、用第2步中备份的.mdf文件覆盖新数据库的同名文件。
8、启动数据库服务。
9、运行alter database dbname set emergency,将数据库设置为emergency mode
10、运行下面的命令就可以恢复数据库:














上面的方法是通过.mdf文件恢复数据库,即使log文件丢失也可以恢复。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· .NET Core 托管堆内存泄露/CPU异常的常见思路
· PostgreSQL 和 SQL Server 在统计信息维护中的关键差异
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· spring官宣接入deepseek,真的太香了~
2004-02-08 全新的搜索功能
2004-02-08 [转帖]Why you can't catch some exceptions