Delphi编程中备份和恢复Access

 

常用的是delphi备份SQL Server,较少用delphi备份Access的,今天有人问了一下,顺便把代码贴出来。有人可能会有需要。

//(***本文出处:南山古桃(nsgtao)的百度空间:http://hi.baidu.com/nsgtao/ ****)
procedure TBackup.Button1Click(Sender: TObject);
var
path:string;
begin
if SaveDialog1.Execute then
if SaveDialog1.FileName <> '' then
begin
path := ExtractFilePath(application.ExeName);
try
copyfile(pchar(path+ 'db.mdb'), pchar(SaveDialog1.FileName+'.bak'), false);
showmessage('备份成功!');
except
showmessage('备份失败,请重试!');
end;
end;
end;

//恢复数据库
//(***本文出处:南山古桃(nsgtao)的百度空间:http://hi.baidu.com/nsgtao/ ****)
procedure TBackup.Button3Click(Sender: TObject);
var
path:string;
begin
if OpenDialog1.Execute then
if OpenDialog1.FileName <> '' then
begin
path := ExtractFilePath(application.ExeName);
try
//(***本文出处:南山古桃(nsgtao)的百度空间:http://hi.baidu.com/nsgtao/ ****)
TBackup.ADOConnection1.Connected := false;
Deletefile(path+'db.mdb');
copyfile(pchar(OpenDialog1.FileName),pchar(path + 'db.mdb'), false);
showmessage('成功恢复数据!');
Application.Terminate;
except
showmessage('恢复失败,请重试!');
end;
end;
end;

转自百度好友 丹墨

你可能感兴趣的:(Delphi编程中备份和恢复Access)