Escolar Documentos
Profissional Documentos
Cultura Documentos
aspx
David Fung
Table "name" has become corrupted. The table will need to be repaired before using again.
It always puzzle me why VFP does not any built-in DBF repair command (not even the simple
one) although it has a native DBF engine.
Lately the frequency of corruption get to a point becomes annoying. So I look around the Net to
see if there is any DBF repair utility which I can incorporate into my app to fix the corruption
automatically when it is detected.
There are some but it is not apparent that they support command line execution or OLE
Automation, and they are not cheap. My client probably doesn't like absorbing the cost of it.
But my client has Excel installed in every workstation, and I noticed that Excel can open the
corrupted DBF okay without any problem. So I wrote a routine to use Excel to repair the DBF. It
simple asks Excel to open the corrupted DBF and save it again. It probably will not repair all
kinds of corruption, but at least it works in my case. Please see if it works for you as a DBF Repair
alternative.
*------------------------------------------------------------------------
* ut_RepairDBF()
*
* Call this routine to repair a DBF file reported by VFP to be corrupted.
*
* PASSES:
* tcFile = The full path to the DBF file to be repaired.
* e.g. 'c:\path\table.dbf'
*
* RETURNS:
* .t. if successful, .f. otherwise.
*
* OUTPUT:
* The original DBF is backup with .bak extension.
* The repaired DBF has the same name as the original file.
*
* EXAMPLE:
* ut_RepairDBF('c:\path\table.dbf')
*
* REMARKS:
* Microsoft Excel is used to repair the DBF.
*------------------------------------------------------------------------
function ut_RepairDBF(tcFile)
1 of 2 10/26/2010 5:36 AM
David Fung : Use Excel to repair DBF http://weblogs.foxite.com/davidfung/archive/2006/10/03/2577.aspx
local lcBackupFile
local lcFixedFile
loExcel = createobject("Excel.Application")
if vartype(loExcel)<>'O'
return .f.
endif
lcBackupFile = alltrim(tcFile)+'.bak'
lcFixedFile = alltrim(tcFile)+'.tmp'
loExcel.Workbooks.Open(tcFile)
loExcel.ActiveWorkbook.SaveAs(lcFixedFile, xlDBF3)
loExcel.ActiveWindow.Close(.f.)
loExcel.Quit()
Comments
2 of 2 10/26/2010 5:36 AM