Avoiding and Fixing a Corrupt Database

Submitted by Support Team on Sat, 04/08/2006 - 8:53am.

If you have ever used an Access database before, you will know that occasionally the database can become corrupted. While the corruption issues happen less often than with early versions of Filemaker, they have happened, to our knowledge, to three users of ODB since 2003 -- all of whom were using older computers to store their ODB 0.9 data, it so happens.

Ways to address corruption (especially on older computers):

A) Avoid the problem by maintaining the computer properly

1) Avoid filling up your hard drive. Keep 50% or more free space.

2) Run the "Defragmentation" tool in Windows every couple of months, overnight if necessary.

3) Install enough RAM on the computer so that the hard drive won't constantly spin (see page 1 of ODB user guide).

4) Set the cache size for Internet explorer to a small size like 5Mb so that web browsing won't put tens of thousands of tiny files on your hard drive, slowing it down.

5) Avoid storing the ODB data on hard drives more than five years old unless you have a tech run a 'surface scan' on the hard drive to make sure it is still in good shape.

B) Maintain the ODB data file, or fix it if there are problems

1) ODB should be automatically maintaining your file for you as part of the monthly backup process. ODB not only backs up the file; ODB will also perform maintenance on it to keep the file compact, automatically. IF THE BACKUP ROUTINE IS GIVING YOU ERRORS, CALL TECH SUPPORT EARLY ON TO FIX THEM, otherwise the necessary maintenance will not be performed.

2) The easiest way to recover from corruption is to go back to an earlier, backed up "good" version of your ODB data file. This may not be a good option if you have done a lot of recent data entry or if all of the recent backups have some minor corruption in them. If you have purchased phone support, the ODB Support Team can walk you though this process.

3) If you have problems using ODB, you can have a tech person run a utility available from Microsoft which might fix these problems. It is called "Jetcomp" and available here:

http://support.microsoft.com/?scid=kb;EN-US;273956

You may also have the ODB Support Team walk you through it if you have purchased phone support. However, as of April 2006 we have never seen an ODB database problem that was fixed by running this utility from Microsoft.

4) The fix that has worked for ODB users is to make a blank copy of the affected database table, and then copy all the good ODB records into that table, then delete the old table and rename the new table to the original name of the old one. This can be done in Access 2000 or in VB. There is a web site at http://www.mvps.org/access/tables/tbl0018.htm explaining this process, but we needed to use VB to make this work. Here is the corrected code:


' This code was originally written by Norm Chezem
' Modified by R. Cowan to work in Visual Basic
' Please refer to original web site for copyright notice
Sub Main()
Dim db As dao.Database
Dim OldRes As dao.Recordset
Dim NewRes As dao.Recordset
Dim FLD As dao.Field
Dim RecCount As Long
On Error GoTo Err_Proc
Set db = dao.OpenDatabase("C:\full-path-to-database-file")
Set OldRes = db.OpenRecordset("SELECT * FROM ---oldtable--- ORDER BY id")
Set NewRes = db.OpenRecordset("---newtable---") ' Before running this, use Access to create a blank copy of table
RecCount = 0
OldRes.MoveFirst
Do While Not OldRes.EOF

Addit:
NewRes.AddNew
'COPY ROW, AND PRESERVE THE id NUMBER HERE....
For Each FLD In OldRes.Fields
NewRes(FLD.Name) = OldRes(FLD.Name)
Next FLD
NewRes.Update

OldRes.MoveNext
RecCount = RecCount + 1
DoEvents
If RecCount Mod 100 = 0 Then
Debug.Print RecCount 'Show progress every 100 rows
If RecCount Mod 10000 Then MsgBox RecCount & " records recovered so far. Click OK to continue."
End If
Loop
MsgBox RecCount & " records recovered. Finished."
OldRes.Close
NewRes.Close
db.Close
Proc_Exit:
Exit Sub
Err_Proc:
MsgBox "" & Err.Description
OldRes.MoveNext 'Skip this corrupt row
Resume Addit 'Continue at Addit
End Sub

Great post! This is a very

Great post! This is a very helpful and extremely informative post. You are right, although errors or corruption are very rare, they do happen. Thanks for posting this. I'm using one somewhat old system (the others are quite recent though) and this really is very helpful. Thanks for posting this.
Stephen
www.shopperarticles.com
Shopping Reviews and Consumer Product Reviews

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.