Thursday, October 18, 2012

How to resolve SQL server database & table corruption


I came across a situation when I was Fetching record from a table, suddenly got below error message for few records: 

Error:- Msg 823, Level 24, State 2, Line 1
The operating system returned error 23(Data error (cyclic redundancy check).) to SQL Server during a read at offset 0x000000344c000 in file 'D:\DB_NAME\DB_NAME.mdf'. Additional messages in the SQL Server error log and system event log may provide more detail. This is a severe system-level error condition that threatens database integrity and must be corrected immediately. Complete a full database consistency check (DBCC CHECKDB). This error can be caused by many factors; for more information, see SQL Server Books Online.

After that I execute DBCC CHECKTABLE ("TABLE_NAME") command on the database & got below error message: 

Msg 8966, Level 16, State 2, Line 1
Unable to read and latch page (1:117) with latch type SH. 23(Data error (cyclic redundancy check).) failed. 
CHECKTABLE found 0 allocation errors and 1 consistency errors not associated with any single object.
DBCC results for 'TABLE_NAME'.
Msg 2533, Level 16, State 1, Line 1
Table error: page (1:117) allocated to object ID 1606, index ID 0, partition ID 7205, alloc unit ID 72057 (type In-row data) was not seen. The page may be invalid or may have an incorrect alloc unit ID in its header.
There are 932 rows in 927 pages for object "TABLE_NAME".
CHECKTABLE found 0 allocation errors and 1 consistency errors in table 'TABLE_NAME' (object ID 1606).
repair_allow_data_loss is the minimum repair level for the errors found by DBCC CHECKTABLE (DB_NAME.dbo.TABLE_NAME).
DBCC execution completed. If DBCC printed error messages, contact your system administrator.

Cause: This error message occurs when database mdf file or database table get corrupted

Suggestion: If you want to find the exact cause of the error then you should run the following command before using any repair option: 

DBCC ChecKDB('<database name>') WITH NO_INFOMSGS, ALL_ERRORMSGS

Most Possible Solutions:


  • Restore your database from updated backup. 
  • If you don't have backup then you should use repair command. If you are the database administrators then you should set the database in single user mode and try DBCC CHECKDB by repair_allow_data_loss option. 
  • Repair command may repair your database or give another error message. It means this error is not repairable by repair command. In this case, you should use Third Party MS SQL Database Recovery Software. These software repairs corrupt database, database files & all database objects including table, triggers, views etc. 


Hope the article will help your to resolve  SQL Server Error "Msg 823, Level 24, State 2, Line 1". 

2 comments:

  1. Thanks you very much. My SQL server 2008 R2 database had corrupted due to physical failure and backup was very old. Tried DBCC CHECKDB repair option and managed to recover my database.

    ReplyDelete
    Replies
    1. Hello Micheal,

      It's good to know that you repaired your database successfully.

      Delete