Главная » Delphi » Базы данных » Compacting a Access DB does also repairing.

Compacting a Access DB does also repairing.

16:49
"AZ" schrieb im Newsbeitrag news:3d34178d_2@dnews...
> Hi,
>
> D6 Ent. MSAccess ADO app.
> How can I repair corrupted MSAccess database programmatically.

Compacting a Access DB does also repairing.


procedure Access_Compact(const aAccess: string);
const
  bak_ext = '.$$$';
  stAccessDB = 'Provider=Microsoft.Jet.OLEDB.4.0;'+
                      'Data Source=%s';
var
  JetEngine : OleVariant;
  TempName : string;
begin
  TempName := ChangeFileExt(aAccess, bak_ext);
  DeleteFile(TempName);
  JetEngine := CreateOleObject('JRO.JetEngine');
  try
    JetEngine.CompactDatabase(
      Format(stAccessDB, [aAccess]),
      Format(stAccessDB, [TempName]));
    DeleteFile(aAccess);
    RenameFile(TempName, aAccess);
  finally
    JetEngine := Unassigned;
  end;
end;
 
 
procedure Access_Compact(const SrcConn, Dstfile: string);overload;
const
  stAccessDB = 'Provider=Microsoft.Jet.OLEDB.4.0;'+
                      'Jet OLEDB:Engine Type=4;'+ //Engine Type=5 (Access2000)
                      'Data Source=%s';
var
   JetEngine : OleVariant;
begin
   JetEngine := CreateOleObject('JRO.JetEngine');
   try
      JetEngine.CompactDatabase(SrcConn, Format(stAccessDB, [dstfile]));
   finally
      JetEngine := Unassigned;
   end;
end;


> Is there a .TLB to provide the interface to JetEngine?
Yes, but it is not worth to import the TLB, because there are only 2
Methods: "CompactDatabase" and "RefreshCache"

"Microsoft Jet and Replication Objects 2.6 Library":
C:\program files\shared files\system\ADO\MSJRO.DLL

greetings
Andreas Schmidt

--
Database Explorer for ADO (Freeware)
http://www.tobilan.de/adodeskexe.zip

[http://216.101.185.148/scripts/isapi.dll/article?id=35B2EFF1&article=3679497]