Here's what I use to do the repair / compact:
// David Reed
function RepairAndCompact(Connection: TADOConnection): integer;
var
FromDb,ToDb: string;
x: integer;
const
ADO_PROVIDER = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=';
begin
// Compacts the database to a NEW database; this is the only way to do
this
Result := 0;
if Connection.Connected then
Connection.Close;
FromDb := Connection.ConnectionString;
x := Pos('Data Source=',FromDb);
if x < 1 then
Exit;
if x > 0 then begin
FromDb := Copy(FromDb,x + 12,255);
Delete(FromDb,Pos(';',FromDb),Length(FromDb));
end;
if FromDb = '' then
Exit;
ToDb := StringReplace(FromDb,'.','_.',[rfReplaceAll]);
while (FileExists(ToDb)) and not (DeleteFile(ToDb)) do
ToDb := StringReplace(FromDb,'.','_.',[rfReplaceAll]);
with TJetEngine.Create(nil) do
try
try
CompactDatabase(ADO_PROVIDER + FromDb,ADO_PROVIDER + ToDb);
if not FileExists(ToDb) then
Exit;
// delete the old file and rename the new one..
if (FileExists(FromDb)) and (DeleteFile(FromDb)) and
(RenameFile(ToDb,FromDb)) then
Result := 1;
except
on E: Exception do
ShowMessage('Message = ' + e.Message);
end;
finally
Free;
end;
end;
--
David Reed
White Plains, Maryland USA
www.diamondsg.com
www.oasisrep.com
*To reply, remove the no_spam from my email address
*To view file attachment(s), remove underscore from file extension