Error: Transaction log file got damaged or corrupted
“An
error occurred while processing the log for database
‘<databasename>’. If possible, restore from backup. If a backup
is not available, it might be necessary to rebuild the log.”
Solution
Below is what I did to rescue my beloved database.1. Enabled emergency mode for that database.
ALTER DATABASE set EMERGENCY
2. Then brought the database into single user mode.
ALTER DATABASE set SINGLE_USER
3. Executed DBCC CHECKDB with repair_allow_data_loss.
DBCC CHECKDB (<databasename>,repair_allow_data_loss) with no_infomsgs
I got below warning in Error Log right after I triggered the CHECKDB command.
Warning:
The log for database ‘<databasename>’ has been rebuilt.
Transactional consistency has been lost. The RESTORE chain was broken,
and the server no longer has context on the previous log files, so you
will need to know what they were. You should run DBCC CHECKDB to
validate physical consistency. The database has been put in dbo-only
mode. When you are ready to make the database available for use, you
will need to reset database options and delete any extra log files.
And once the CHECKDB completed, The errorlog log reported below message which made me very happy.
EMERGENCY
MODE DBCC CHECKDB (<databasename>, repair_allow_data_loss) WITH
no_infomsgs executed by SPANSION\admin_sponnamb found 0 errors and
repaired 0 errors. Elapsed time: 0 hours 52 minutes 54 seconds.
After the CHECKDB completed, I reverted back the database into multiuser mode with below command.ALTER DATABASE <databasename> SET MULTI_USER
Now the application was successfully able to access the database and everything was function very well as expected. A full backup has to be triggered to reset LSN numbers and to take transaction log backups.