Wiki Home

Table Has Become Corrupted


Namespace: VFP
One of our clients data had become damaged. Running the application produced C0000005 errors and out of memory messages.

After obtaining their data, I encountered Table Has Become Corrupted errors during my analysis. See Not ATable for further information on the cause of these errors.

After reviewing FoxWiki, I tried a few of the UDF's for repairing the tables without success. I then wrote the following program to manually correct the damaged tables. I thought it might be useful to someone else.

SET TABLEVALIDATE TO 3
CD D:\application\data

OPEN DATABASE appdata EXCLUSIVE
VALIDATE DATABASE TO FILE before.txt

lnDBF = ADIR(laDBF,"*.dbf")
FOR i = 1 TO lnDBF
  TRY
    USE (laDBF[i,1]) EXCLUSIVE
  CATCH
    SET TABLEVALIDATE TO 0
    USE (laDBF[i,1]) EXCLUSIVE

    MESSAGEBOX("Table "+laDBF[i,1]+" could not be opened. "+CHR(13)+;
                           "Please delete any damaged records (Ctrl-T). "+CHR(13)+;
                           "Press Ctrl-W when finished",16)

    BROWSE
    SET TABLEVALIDATE TO 3
  FINALLY
    PACK
    REINDEX
  ENDTRY
NEXT
VALIDATE DATABASE RECOVER TO FILE after.txt



I also want to note that many times it is better to delete the indexes and recreate them instead of just issuing the REINDEX command.

Brian Marquis

Category Data Corruption
( Topic last updated: 2006.02.03 12:14:33 PM )