Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Table 'c:\mydata.dbf' has become corrupted table will ne
Message
From
14/05/2004 07:41:09
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00903499
Message ID:
00904005
Views:
19
>table 'c:\mydata.dbf' has become corrupted table will need to repaired before used again :( how can i repair this corrupted dbf file
>
>TIA

Old code but it still works fixing a corrupted record count value in the header - the most common cause of DBF corruption. Try this AFTER you make a back up copy of your table:
**********************************************************************
*  Program Name:   FIXRECNT.PRG
*  Purpose:        Rewrite correct RECCOUNT() value to DBF header
*  Date Written:   06/28/93
*  Modified:       08/11/93
*  Usage:          If dbf name = TEMP.DBF
*			   DO fixrecnt WITH "temp.dbf" OR =fixrecnt("temp.dbf")
*********************************************************************
PARAMETERS lcfname
PRIVATE ALL LIKE l*

IF AT('.',lcfname) = 0
	? CHR(7)
	WAIT WINDOW "File name with extension is required..." 
	RETURN
ENDIF

lnhandle     =FOPEN(lcfname,12)		&& Open w/unbuffered read/write
IF lnhandle  = -1						&& Test for error
	WAIT WINDOW "Error: "+STR(FERROR(),2)
	RETURN
ENDIF
lchdrinfo  =FREAD(lnhandle,12)		&& Read first 12 characters 

* Calculate the header length
lnhdrsize  = INT(ASC(SUBSTR(lchdrinfo,09,01)) ;
			   + ASC(SUBSTR(lchdrinfo,10,01)) * 256)
* Calculate the record length
lnreclngth = INT(ASC(SUBSTR(lchdrinfo,11,01)) ;
               + ASC(SUBSTR(lchdrinfo,12,01)) * 256)

************************************************************************
*  ADIR returns file statistics into the array named 'lafsize'.  The
*  variable 'lnreccnt' calculates the record count by subtracting the
*  header length from the file size and dividing the result by the
*  record length.
************************************************************************
=ADIR(lafsize,lcfname)			
lnreccnt   = INT((lafsize[2] - lnhdrsize) / lnreclngth)

************************************************************************
*  Modulus division is used to return the remainder of division by 256 
*  taken to a decreasing exponent power.
************************************************************************
lcfirst8   = LEFT(lchdrinfo,4) + SPACE(4)
FOR lni = 3 TO 0 STEP -1
	lcfirst8 = STUFF(lcfirst8,lni+5,1,CHR(INT(lnreccnt / 256^lni)))
	lnreccnt = lnreccnt % 256^lni
ENDFOR

=FSEEK(lnhandle,0,0)			&& Go to the top of the file
=FWRITE(lnhandle,m.lcfirst8)	&& Write 1st 4 positions & RECCOUNT() val
=FCLOSE(lnhandle)				&& Close the file

RETURN
* EOF fixrecnt.prg
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform