Delphi压缩access数据库

function CompactMDB(const DBFile, Pwd: string): boolean;
var
  TempDBFile: string;
  ConStr: string;
  JE: OleVariant;
begin // Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=..\Data\alarm.mdb;Mode=Share Deny None;Jet OLEDB:System database="";Jet OLEDB:Registry Path="";Jet OLEDB:Database Password="";Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="";Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False;
  ConStr := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;' +
    'Jet OLEDB:Database Password=HYGEA;';
  TempDBFile := ExtractFilePath(Application.ExeName) + 'TEMP.mdb';
  try
    JE := CreateOleObject('JRO.JetEngine');
    JE.CompactDatabase(Format(ConStr, [DBFile, Pwd]),
      Format(ConStr, [TempDBFile, Pwd]));
    Result := CopyFile(PChar(TempDBFile), PChar(DBFile), False);
    DeleteFile(PChar(TempDBFile));
  except
    Result := False;
  end;
end;


procedure THCMainForm.HCMaintenanceFrameButton7Click
                (Sender: TObject);
              begin
                CompactMDB(ExtractFilePath(Application.ExeName) + 'alarm.mdb',
                  '');
              end;
相关文章

相关标签/搜索