请问如何压缩加了密码的ACCESS数据库??不使用ODBC而用连接字符串,没有加密码的ACCESS数据库压缩成功而加了密码就失败,为什么?如何做??高手指教!!!
解决方案 »
- 请哪位帮忙实现一下DOS下的fsplit函数,谢谢
- Ado Post时出错
- 怎么设置windows全局热键????就像qq的唤出对话窗口的热键?
- 怎样把两副图片合在一起?又可以分开?
- 关于stringGrid的Cell内容修改恢复及显示格式问题。。。
- 哪里可以下载能使用的InstallShield Express Custom Edition for Delphi
- 问题还未解决呢,请各位救救小弟弟吧!!!!
- 给这段代码加注释!
- 如何在程序动行时改变 Adodataset的locktype。
- Ado控件的问题。
- 100分急求,在线等
- 请问如何改变用MessageBox产生的提示框的背景颜色啊???急、急、急
const
sProvider='Provider=Microsoft.Jet.OLEDB.4.0;';
var
oJetEng:JetEngine;
begin
if password then
sOldMDB:=sProvider+'Data Source='+sOldMDB+';jet oledb:database password="'+psw+'"'
else
sOldMDB:=sProvider+'Data Source='+sOldMDB;
if password then
sNewMDB:=sProvider+'Data Source='+sNewMDB+';jet oledb:database password="'+psw+'"'
else
sNewMDB:=sProvider+'Data Source='+sNewMDB;
try
oJetEng:=CoJetEngine.Create;
oJetEng.CompactDatabase(sOldMDB, sNewMDB);
oJetEng:=Nil;
Result:=True;
except
oJetEng:=Nil;
Result:=False;
end;
end; {10.CompactAndRepair(压缩Access数据库,用到JRO_TLB单元,可按下面方法加入) }
{ a) 在Delphi IDE中选择Project - Import Type Library. }
{ b) 往下翻直到你找到“Microsoft Jet and Replication Objects 2.1 Library”.}
const NewPWD: string = ''; const MDBType: string = '97'): Boolean;
//压缩修复MDB数据库,也可修改数据库口令;
//MDBName数据库文件名,OLDPWD旧口令,NEWPWD新口令。
var
MyJetEngine: JetEngine;
sTempFile, sOldJRO, sNewJRO: string;
begin
Result := False;
//Check file exist.
if not FileExists(MDBName) then
begin
raise Exception.Create('MS Access数据库:' + #13 + MDBName + #13
+ '不存在!');
Exit;
end;
//Set environment
sTempFile := GetTempFile;
sOldJRO := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + MDBName;
sNewJRO := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + sTempFile;
if MDBType = '97' then
begin
sOldJRO := sOldJRO + ';Jet OLEDB:Engine Type=4';
sNewJRO := sNewJRO + ';Jet OLEDB:Engine Type=4';
end
else if MDBType = '2000' then begin
sOldJRO := sOldJRO + ';Jet OLEDB:Engine Type=5';
sNewJRO := sNewJRO + ';Jet OLEDB:Engine Type=5';
end
else begin
raise Exception.Create('本函数不支持建立其他格式的MS Access数据库!');
Exit;
end;
if OldPWD <> '' then
sOldJRO := sOldJRO + ';Jet OLEDB:Database Password=' + OldPWD;
if NewPWD <> '' then
sNewJRO := sNewJRO + ';Jet OLEDB:Database Password=' + NewPWD;
//Compact
try
try
MyJetEngine := CoJetEngine.Create();
MyJetEngine.CompactDatabase(sOldJRO, sNewJRO);
Result := True;
except
raise Exception.Create('无法修复和压缩MS Access ' + MDBType + ' 数据库:'
+ #13 + MDBName);
end;
finally
MyJetEngine := nil;
end;
//Rename file.
if not Result then
Exit;
//Copy File
if not CopyFile(PChar(sTempFile), PChar(MDBName), False) then
begin
raise Exception.Create('无法复制文件!');
Result := False;
Exit;
end;
//Delete temp file.
if not DeleteFile(PChar(sTempFile)) then
begin
raise Exception.Create('无法删除临时文件!');
Result := False;
Exit;
end; Result := True;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
if CompactRepairMDB(gs_dbname,'Roadster','Roadster','2000') = false then
Application.MessageBox('压缩和修复过程出现错误!!','数据库工具',Mb_Ok+Mb_IconError)
else
Application.MessageBox('恭喜,已成功压缩和修复!','数据库工具',Mb_Ok+Mb_IconInformation);
end;