Recently one of our Staging Database Server hosted in the United States of America suddenly got Rebooted after which one of the database named ABC hosted on the server went into the SQL Server SUSPECT mode. The database was hosted on a SQL Server 2000 platform with Service Pack 3 on a Windows Server 2003 R2 Enterprise Edition machine.
Due to a sudden Reboot the Transactional Log file of the database named ABC got corrupted due to which the database went into SUSPECT mode. Since database got marked as SUSPECT it meant that the Application will not be able to connect to the database which will in turn have a very bad impact on the Business Users as they won’t be able to perform their testing. At the same time when the Transactional Log file of the database got corrupted, the Backup Drive B present on the server also got corrupted which meant that I will never have the Latest Full Backup to recover the Data Back. Looking at the entire situation, I decided to implement the below solution to repair the database. Please keep in mind that this solution is the one which shall be used only at the worst stage, i.e. when the Transactional Log File of the database gets corrupted and you do not have any Backups to recover your data back.
I decided to find the Physical Location of the Transactional Log file of the database named ABC by executing the below T-SQL against the master database on the server.
Select * from sysaltfiles
I got the Physical location of the Transactional Log file of the database named ABC. It was as follows:
After getting the Physical Location, I stopped the SQL Server Services on the server. Since it was a Stand Alone machine and not a cluster therefore I stopped the services by selecting the same from services.msc .
I decided to rename the Transactional Log File of the database as ABC_1.ldf. Please note that you need to be an administrator on the server to rename the file.
Allow the SQL Server to perform the system changes by executing the below T-SQL.
EXEC sp_configure ‘Allow updates’, ‘1’
Reconfigure with override
Set the database named ABC to Emergency mode by executing the following query against the master database on the server.
SET Status = -32768
WHERE [Name] = ‘ABC’
Once the database is set to EMERGENCY mode it becomes a READ_ONLY copy and only members ofsysadmin fixed server roles have privileges to access it.
Bring the database named ABC to Single User mode by using the below T-SQL:
EXEC sp_dboption ‘ABC’, ‘Single User’,’TRUE’
The next step would be to Rebuild the Transactional Log file of the database using the below T-SQL.
DBCC REBUILD_LOG (‘ABC’,’D:\MSSQL\Data\ABC.LDF’)
Where ‘D:\MSSQL\Data\ABC.LDF’is the original path and name of the Transactional Log File.
Run DBCC CHECKDB as follows to ensure that the database is free from any sort of corruption:
DBCC CHECKDB (‘ABC’)
If DBCC CHECKDB doesn’t print any error message then it means that we are successful.
Go to Database Properties and Uncheck the DBO User Only Restricted Access option.
This was one such approach that we used to recover the database back since we lost our database backups. Please do let us know in case if there are any other suggestions for the same, any approach which can be more effective and useful. Please feel free to drop your suggestions\queries on firstname.lastname@example.org and I would be glad to assist you.