Alaska Software Inc. - Re: corrupted dbf file structure
Username: Password:
AuthorTopic: Re: corrupted dbf file structure
Andreas Gehrs-Pahl

View the complete thread for this message in:

Re: corrupted dbf file structure
on Wed, 17 Feb 2016 18:23:34 -0500
Tomasz,

>if the file.dbf is corrupted and open it as follows
[...]
>the file is open and there is no way to close it. it seems to me that it 
>should be automatically closed if it has a bad structure.

What do you mean with "corrupted" and "there is no way to close it"? Can you 
post a "corrupted" file and a compilable program that shows the issue?

In general, I would change your code to something like this:

LOCAL bl := ErrorBlock({|e| Break(e)})
LOCAL ok := .f.
   Begin Sequence
      DbUseArea(.t., , 'c:\data\file.dbf', 'file', .t.)
      ok:= .t.
   Recover Using oError
      ErrorBlock(bl)
*     Write the oError (and other) info to your Error Log here...
      MsgBox('Error opening file: file.dbf')
   End Sequence
   ErrorBlock(bl)

   if ok
*      More code here...
   endif

I use a similar (though more complex) routine to open database files, and I 
don't think that I have seen any issues with handling corrupted Databases 
(or Index files) with it.

Hope that helps,

Andreas

Andreas Gehrs-Pahl
Absolute Software, LLC

phone: (989) 723-9927
email: Andreas@AbsoluteSoftwareLLC.com
web:   http://www.AbsoluteSoftwareLLC.com