Answered by:
error 9003 when attaching a database

Question
Answers
-
Hello,
Do you mean this error:
The log scan number %S_LSN passed to log scan in database '%.*ls' is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup.As the message already says, one option is to restore the database from the last valid backup.
Other options is:
- Detach the database
- Rename/Move the log file
- Attach the MDF database file without the LOG file; a new log will be created.
Olaf Helper
Blog Xing- Edited by Olaf HelperMVP, Moderator Wednesday, March 6, 2013 8:20 AM
- Proposed as answer by Ed Price - MSFTMicrosoft employee, Owner Wednesday, March 6, 2013 8:51 AM
- Marked as answer by Maggie LuoModerator Wednesday, March 13, 2013 5:01 PM
All replies
-
Do you have a last good backup of that db?
Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Blog: Large scale of database and data cleansing
Remote DBA Services: Improves MS SQL Database Performance
-
Hello,
Do you mean this error:
The log scan number %S_LSN passed to log scan in database '%.*ls' is not valid. This error may indicate data corruption or that the log file (.ldf) does not match the data file (.mdf). If this error occurred during replication, re-create the publication. Otherwise, restore from backup if the problem results in a failure during startup.As the message already says, one option is to restore the database from the last valid backup.
Other options is:
- Detach the database
- Rename/Move the log file
- Attach the MDF database file without the LOG file; a new log will be created.
Olaf Helper
Blog Xing- Edited by Olaf HelperMVP, Moderator Wednesday, March 6, 2013 8:20 AM
- Proposed as answer by Ed Price - MSFTMicrosoft employee, Owner Wednesday, March 6, 2013 8:51 AM
- Marked as answer by Maggie LuoModerator Wednesday, March 13, 2013 5:01 PM
-
Was the database cleanly shutdown? If Yes then try to attach database without ldf file, ldf file will be automatically created for the database.
Bellow steps help in case of database was not cleanly shutdown.
- Create a same size database
- Now shutdown the SQL server
- Change the old mdf file with new one
- Start the SQL server, your database may go in suspect mode
- Now change your database status from suspect mode to emergency mode by ALTER Database command
- Run DBCC CHECKDB with REPAIR_ALLOW_DATA_LOSS. It will rebuild the log and run full repair
Note: You may loss some amount of database by performing above steps. Try it as a last resort.