Friday, April 11, 2008

Restoring Microsoft SQL database file


There is a time i faced Microsoft SQL Server database log file corruption problem on the POS machine i worked on. I googled many sites for different sources on restoring the corrupted log file for few days. At the end, all the sources i found is not applicable to the problem i faced. Sweat -.-'''

Well, some how, i was able to find a site for restoring the log fle. This solution help me restore the MSSQL server log file and the database is working fine after restoring the log file.

Bellow are the steps on restoring the log file :-

RESTORING MS SQL SERVER LOG FILE
1. Create a new database with the same name and same MDF and LDF files

2. Stop sql server and rename the existing MDF to a new one and copy the original MDF to this location and delete the LDF files.

3. Start SQL Server

4. Now your database will be marked suspect

5. Update the sysdatabases to update to Emergency mode. This will not use LOG files in start up

Sp_configure "allow updates", 1
go
Reconfigure with override
GO
Update sysdatabases set status = 32768 where name = "BadDbName"
go
Sp_configure "allow updates", 0
go
Reconfigure with override
GO
6. Restart sql server. now the database will be in emergency mode

7. Now execute the undocumented DBCC to create a log file
DBCC REBUILD_LOG(dbname,'c:\dbname.ldf') -- Undocumented step to create a new log file. (replace the dbname and log file name based on ur requirement)

8. Execute sp_resetstatus

9. Restart SQL server and see the database is online.
Hope these steps helps you to restoring the corrupted log file.

3 comments:

whisper said...

Good n detail advice..Hm, last time I also encountered a problem almost like tis wor, the Log file n Mdf file which set by program default cannot be created, so i rename the Mdf and Log to other names, at different folder, then just can work.

Derren said...

wahaha... i did read from one article which the suggested way is same as ur's. But it just not work on my cituation... hoho -.-

Alexis said...

For work with sql files I often use-recovery database sql.On next reasons: tool solved all my problems with sql files quickly and easy.Moreover it was for free and program demonstrated repair data from corrupted databases in the MS SQL Server format (files with the *.mdf extension).