Alaska Software Inc. - corrupted dbf file structure
Username: Password:
AuthorTopic: corrupted dbf file structure
Tomasz Adamczykcorrupted dbf file structure
on Wed, 17 Feb 2016 14:05:15 +0100
if the file.dbf is corrupted and open it as follows


bl:=errorblock({|e| break(e)})
ok:= .f.
begin sequence
  dbusearea(.t. , 'c:\data\file.dbf' , 'file', .t.)
  dbselectarea('file')
  ok:= .t.
endsequence
errorblock(bl)

if !ok
   msgbox('Error opening file: file.dbf')
endif

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.

Tomasz Adamczyk
Matej JuracRe: corrupted dbf file structure
on Wed, 17 Feb 2016 15:19:41 +0100
You have error in function call, because in place of driver you put in a filename

dbusearea(.t. , 'c:\data\file.dbf' , 'file', .t.)

this should be for default driver
dbusearea(.t. , ,'c:\data\file.dbf' , 'file', .t.)

M



Tomasz Adamczyk wrote in message
news:6a626653$20b45e60$160e1f@news.alaska-software.com...
>if the file.dbf is corrupted and open it as follows
>
>
>bl:=errorblock({|e| break(e)})
>ok:= .f.
>begin sequence
>  dbusearea(.t. , 'c:\data\file.dbf' , 'file', .t.)
>  dbselectarea('file')
>  ok:= .t.
>endsequence
>errorblock(bl)
>
>if !ok
>   msgbox('Error opening file: file.dbf')
>endif
>
>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.
>
>Tomasz Adamczyk
Tomasz AdamczykRe: corrupted dbf file structure
on Wed, 17 Feb 2016 16:01:54 +0100
of course. mistake only in my post. In source is OK.
thx for your answer.


Użytkownik "Matej Jurac" napisał w wiadomości grup 
dyskusyjnych:5eb23c2d$784a5e5c$161058@news.alaska-software.com...

You have error in function call, because in place of driver you put in a 
filename

dbusearea(.t. , 'c:\data\file.dbf' , 'file', .t.)

this should be for default driver
dbusearea(.t. , ,'c:\data\file.dbf' , 'file', .t.)

M



Tomasz Adamczyk wrote in message
news:6a626653$20b45e60$160e1f@news.alaska-software.com...
>if the file.dbf is corrupted and open it as follows
>
>
>bl:=errorblock({|e| break(e)})
>ok:= .f.
>begin sequence
>  dbusearea(.t. , 'c:\data\file.dbf' , 'file', .t.)
>  dbselectarea('file')
>  ok:= .t.
>endsequence
>errorblock(bl)
>
>if !ok
>   msgbox('Error opening file: file.dbf')
>endif
>
>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.
>
>Tomasz Adamczyk
Andreas Gehrs-Pahl
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