Need guidance to prevent database corruption
I have developed a software using C# (.Net 4.0) and SQLExpress 2008 Edition. The problem I am facing is that the database is corrupted too frequently. I need guidance why the database is corrupted and How it can be prevented from corruption. There are three scenarios of corruption:
  • Case 1: Database is corrupted with following error or similar: Error: 9003, Severity: 20, State: 9. The log scan number (180:371:2) passed to log scan in database 'MyDatabase' 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. This type of corruption can be repaired and data is recovered. In most case, the similar corruption occurred.
  • Case 2: One of the system database like master or tempdb is corrupted with error similar to above error. In this case the sql service is stopped. I need to replace the files of system databases. Sometime the sql service is started and sometimes it do not. Then I have to re-install the SQLExpress server. This problem is rarely occured.
  • Case 3: Database is corrupted with following error: Error: 824, Severity: 24, State: 2. SQL Server detected a logical consistency-based I/O error: incorrect checksum (expected: 0xb956dcc; actual: 0xb956d68). It occurred during a read of page (1:337) in database ID 5 at offset 0x000000002a2000 in file '[MDF File Path]'.  Additional messages in the SQL Server error log or system event log may provide more detail. This is a severe 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. DBCC CHECKDB ([MyDatabase]) WITH all_errormsgs, no_infomsgs executed by d-PC\d terminated abnormally due to error state 5. Elapsed time: 0 hours 0 minutes 1 seconds. Setting database option AUTO_CLOSE to OFF for database MyDatabase. This type of corruption can not be repaired and data is not recovered. This type of corruption is most rare.
I need guidance why these situations arise and how can these situations be prevented so that I can add preventive measures in software.
March 17th, 2015 11:42am

Data corruption can happen for all sorts of reasons but the some issues tend to be hardware related, indexes getting out of sync or when a bulk data task cannot be handled efficiently when a database is in full logging mode.

If there are any bulk data tasks happening on the Database, especially overnight, then try setting the database to "BULK LOGGED" before running such processes and then back to "FULL" when these processes are finished.  Note these processes can be deletes, updates and inserts.

If there are large tables in your database then try and limit the Index Rebuilds to once a week and just use reorganise through the week.

Another issue can be where the backups get out of sync.  Perform a full Database backup if this occurs.

Free Windows Admin Tool Kit Click here and download it now
March 17th, 2015 11:49am

Physical database corruption by SQL Server itself is extremely rare. 

This is almost always caused by something external, either bad RAM, disk drive, disk controller, write back cache or something else interfering with writing to disk.

March 17th, 2015 12:38pm

I have developed a software using C# (.Net 4.0) and SQLExpress 2008 Edition. The problem I am facing is that the database is corrupted too frequently. I need guidance why the database is corrupted and How it can be prevented from corruption.

"Too" frequently??

If you encounter corruption you should immediately check your IO subsystem.

If you keep getting corruption, serious trouble is ahead. So please make sure you find the cause of the error, probably being a disk that will fall out soon.

Once the cause is resolved setting the Databases to Pageverify = Checksum + regular consistency checks with DBCC CHECKDB and having a long enough backup-chain should be sufficient.

Free Windows Admin Tool Kit Click here and download it now
March 17th, 2015 12:50pm

There are no bulk data tasks but there is a table in the database on which Inserts and Updates performed can go up to 500-600 times in 24 hrs. Does that matters?

March 19th, 2015 3:10am

The most common scene that comes to my mind is:

The software has backup enabled on software exit. At that times, sometimes customers forcefully ends the software from task manager. Does this can be a issue?

Free Windows Admin Tool Kit Click here and download it now
March 19th, 2015 3:13am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics