1813 error when attaching mdf database without ldf log to MS SQL Server 2008 r2

 Solution:
  1. First, back up the mdf file, otherwise the fun will be great.
  2. Create a new database with the same name in the database. For example [DM]
  3. Stop the SQL Server service
  4. Find the folder where the database is located, and delete the DM_log.ldf and DM.mdf files
  5. Copy the database [DM.mdf] file that needs to be attached to the current path.
  6. Start the SQL Server service and connect to the database through the Enterprise Manager.
  7. The new database address in step 1 has already pointed to the mdf file where you need to attach the database. But now the database still cannot be opened.
  8. Execute statement: ALTER DATABASE DM SET EMERGENCY
  9. Execute statement: ALTER DATABASE DM SET SINGLE_USER
  10. Execute statement: ALTER DATABASE DM REBUILD LOG ON (NAME=DM_log, FILENAME='F:\MSSQL2008\DATA\DM_log.ldf' )
  There may be two problems in this step:
        a. If the database file cannot be manipulated, the permission to modify the DM.mdf file is full control.
        b. Where FILENAME is the path where you need to create a new ldf log and the name of the ldf file. There will be a warning "After execution, there will be a warning message "WARNING: The log for database 'xhtyjbbs' has been regenerated. Transaction consistency has been lost. The RESTORE chain is broken, the server no longer has the context of the previous log files, so you need to know their content. DBCC CHECKDB should be run to verify physical consistency. The database has been placed in dbo-only mode. When you are ready to make the database available, you need to reset the database options and delete any redundant log files. "Ignore this step, and execute the following step

  11. DBCC CHECKDB(DM, REPAIR_ALLOW_DATA_LOSS)    
          will compare the cards, which may cause the interface to not respond. Wait a while. After success, the database will become single-user mode, and the following two steps will be modified to Multi-user mode.
  12. ALTER DATABASE DM SET MULTI_USER
  13. ALTER DATABASE DM SET ONLINE

Reference: http://www.cnblogs.com/clownkings/p/4950865.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326513638&siteId=291194637