http://guohongjian81.blog.163.com/blog/static/34535941201262924347173/

常用的是delphi备份SQL Server,较少用delphi备份Access的,今天有人问了一下,顺便把代码贴出来。有人可能会有需要。(使用的是文件复制和替换方式

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;

//恢复数据库
procedure TBackup.Button3Click(Sender: TObject);
var
path:string;
begin
if OpenDialog1.Execute then
if OpenDialog1.FileName <> '' then
begin
path := ExtractFilePath(application.ExeName);
try

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;