简体   繁体   English

从MDF文件还原数据库,丢失的LDF和数据库未完全关闭

[英]Restore DB from MDF file, lost LDF and DB was not cleanly shutdown

My dev DB server was formatted by some admin without my knowledge. 我的开发数据库服务器是由某些管理员在不知情的情况下格式化的。 Thankfully I had .mdf file kept in some other drive but .ldf was in its default location. 幸运的是,我将.mdf文件保存在其他驱动器中,但.ldf处于其默认位置。 Since I don't have DB backup I am now left with .mdf file. 由于我没有数据库备份,因此现在只剩下.mdf文件。 I googled and found various tricks to restore DB from .mdf file. 我用谷歌搜索,发现了各种技巧来从.mdf文件还原数据库。 Since database was not cleanly shutdown none of the tricks worked. 由于没有彻底关闭数据库,因此没有任何技巧可以起作用。 I have SQL Server 2008 SP2 installed in my machine. 我的机器上安装了SQL Server 2008 SP2。 As I remember lost DB server was SQL Server 2005 instance. 我记得丢失的数据库服务器是SQL Server 2005实例。 Please let me know how I could recover my database. 请让我知道如何恢复数据库。

Tricks i tried: 我尝试过的技巧:

  1. I tried to attach the .mdf from SSMS by removing the log file item from database to attach list. 我试图通过从数据库到附加列表中删除日志文件项来附加来自SSMS的.mdf。
  2. CREATE DATABASE Monitoring ON (FILENAME = N'D:\\Dump\\Data\\Monitoring.MDF') FOR ATTACH_REBUILD_LOG
  3. sp_attach_single_file_db N'Monitoring', N'D:\\Dump\\Data\\Monitoring_Data.MDF'

In all above I got 在以上所有内容中

Incorrect DBCC statement. DBCC语句不正确。 Check the documentation for the correct DBCC syntax and options. 检查文档以获取正确的DBCC语法和选项。

Then I tried DBCC REBUILD_LOG('Monitoring',N'C:\\Program Files ..MSSQL\\Data\\Monitoring_log.ldf') which resulted in: 然后我尝试了DBCC REBUILD_LOG('Monitoring',N'C:\\Program Files ..MSSQL\\Data\\Monitoring_log.ldf') ,结果是:

Incorrect DBCC statement. DBCC语句不正确。 Check the documentation for the correct DBCC syntax and options.” error. 检查文档以获取正确的DBCC语法和选项。”错误。

Here are some notes (for SQL 2000) that might help. 以下是一些注释(对于SQL 2000)可能会有所帮助。 I've never tried these personally. 我从来没有亲自尝试过这些。

  1. In EM create a DB with the same name as the original. 在EM中,创建一个与原始数据库同名的数据库。
  2. Stop the SQL service (instance). 停止SQL服务(实例)。
  3. Copy the old .MDF over the new one. 将旧的.MDF复制到新的。
  4. Start the service (instance). 启动服务(实例)。
  5. DB will appear as suspect in EM. 数据库将在EM中显示为可疑。
  6. Fire up Query Manager. 启动查询管理器。
  7. Connect to the running instance. 连接到正在运行的实例。
  8. Put the DB into Emergency Bypass Status by doing the following: 通过执行以下操作,将数据库置于紧急旁路状态:

     sp_configure 'allow', 1 go reconfigure with overide. update master..sysdatabases set status=32768 where dbid=5 --check this ID is for your db 
  9. Stop the SQL service (instance). 停止SQL服务(实例)。

  10. Delete the LDF. 删除LDF。
  11. Start the SQL service (instance). 启动SQL服务(实例)。
  12. Execute the following in QM: 在质量管理中执行以下步骤:

     select dbid, status, name from master..sysdatabases dbcc rebuild_log ('dbname', 'full path and LDF name') 
  13. Revert DB from Emergency Bypass Status by executng in QM: 通过在QM中执行,从紧急旁路状态还原DB:

      update master..sysdatabases set status=16 where dbid=5 --Check this ID for your db 
  14. Cleanup by executing the following in QM: 通过在QM中执行以下操作进行清理:

      sp_configure 'allow', 0 go reconfigure with override 

Try This: 尝试这个:

ALTER DATABASE EmpDataBase REBUILD LOG ON (NAME=$DatabaseName$,FILENAME=N'$Path\\DatabaseName.ldf$') ALTER DATABASE EmpDataBase重建登录(NAME = $ DatabaseName $,FILENAME = N'$ Path \\ DatabaseName.ldf $')

GO

DBCC CHECKDB DBCC CHECKDB

ALTER DATABASE $DatabaseName$ SET MULTI_USER ALTER DATABASE $ DatabaseName $ SET MULTI_USER

GO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用T-SQL或.net代码将Mdf / ldf数据库文件转换为.bak文件(db restore) - how to convert Mdf/ldf database files to .bak file (db restore) using T-SQL or .net code 将数据库从单个mdf还原到多个mdf数据库 - Restore DB from single mdf to multiple mdf DB 确定MDF和LDF文件匹配 - Determine MDF and LDF file match 如何通过C#以编程方式在不使用.mdf或.ldf文件的情况下将.bak文件还原到新服务器? - How can I restore a .bak file to a new server without using the .mdf or .ldf files, programmatically with C#? SQL Server还原错误:文件“db.mdf”的目录查找失败 - SQL Server Restore Error: Directory lookup for the file “db.mdf” failed 设置用于备份和还原SQL Server数据库的指令(更改.mdf和.log文件) - Instructions set for backup and restore of SQL Server's DB (changing .mdf and .log file) 附加没有 LDF 文件的 MDF 文件 - Attaching an MDF file without LDF file 通过复制mdf和ldf文件备份数据库 - Backup database by copy mdf and ldf file 如果从机器上删除了 .mdf 和 .ldf 文件,如何从 SQL Server 中删除数据库? - How to delete database from SQL Server if .mdf and .ldf file is removed from the machine? 如何使用c#从文件系统和SQL Server中删除动态生成的数据库文件(.MDF和.LDF) - How to delete a dynamically generated database file (.MDF and .LDF) from the filesystem and from SQL server using c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM