- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 优化MDB文件
uses ComObj;
procedure CompactMdb(
SourceMdbPath, SourceMdbPassword,
TargetMdbPath, TargetMdbPassword: String);
const
SOURCE_PARAM = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Database Password=%s';
TARGET_PARAM = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s;Jet OLEDB:Engine Type=%d;Jet OLEDB:Database Password=%s';
ENGINE_TYPE = 5; //Jet OLEDB:Engine类型
var
Engine: OleVariant;
SourceStr, TargetStr: String;
begin
SourceStr := Format(SOURCE_PARAM, [SourceMdbPath, SourceMdbPassword]);
TargetStr := Format(TARGET_PARAM, [TargetMdbPath, ENGINE_TYPE, TargetMdbPassword]);
Engine := ComObj.CreateOleObject('JRO.JetEngine');
Engine.CompactDatabase(SourceStr, TargetStr);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
CompactMdb('C:\mdb\old.mdb', 'pass1','C:\mdb\new.mdb', 'pass2');
end;