How to deal with SQL Server database error 9003 (LSN is invalid)

1. First backup the files ufdata_Data.MDF and ufdata_Log.LDF corresponding to the damaged database to other places;
2. Create a database with the same name as the damaged database in SQL Server and Enterprise Manager, and the corresponding database file names are also ufdata_Data.MDF and ufdata_Log.LDF;
3. Stop the SQL  Server service;
4. Delete the ufdata_Log.LDF file generated by the new database in step 2;
5. Overwrite the ufdata_Data.MDF file generated by the new database in step 2 with the damaged database data file ufdata_Data.MDF
6. Start the SQL  Server service;
7. Enter the Enterprise Manager and refresh the database status. At this time, the status of the database ufdata_004_2007 is "doubtful";
8. Set the SQL  Server database server "Allow direct modification of system catalogs" in the SQL  Server server properties
9. Start SQL  Query Analyzer from the Tools menu of SQL Enterprise Manager ;
10. Enter the following code and run to put the ufdata_004_2007 database into emergency repair mode:
update sysdatabases set status=-32768 where dbid=DB_ID('ufdata_004_2007')
  After this statement is executed, refresh the Enterprise Manager, and the status of the ufdata_004_2007 database becomes "read-only\doubt\offline\emergency mode".
11. Enter the following statement and execute the rebuild log file;
dbcc rebuild_log('ufdata_004_2007','D:\MYDATA\MyDB_Log.LDF')
  After this statement is executed, refresh the Enterprise Manager, and the status of the ufdata_004_2007 database becomes "DBO only".
12. Enter and execute the positive statement to set the database ufdata_004_2007 to the normal state;
exec sp_dboption 'ufdata_004_2007','dbo use only','false'?
  After this statement is executed, refresh the Enterprise Manager, and the ufdata_004_2007 database becomes normal.
?At this point, the ufdata_004_2007 database is successfully repaired. Finally don't forget to turn off the "Allow direct modifications to system directories" server switch that was turned on in step 8.

Guess you like

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