//数据备份
var
Str_Path:string;
begin
SaveDialog1.Filter := '所有文件(*.*)|*.*';
SaveDialog1.Title := '选择备份路径和文件名';
if SaveDialog1.Execute=true then
begin
Str_Path:=SaveDialog1.FileName;
end;
if Str_Path<>'' then
begin
with DM.QSJBF do
begin
try
Screen.Cursor := crHourGlass;
DM.QSJBF.Close;
DM.QSJBF.SQL.Clear;
DM.QSJBF.SQL.Add(' BACKUP DATABASE 物流管理系统 TO DISK ='+'''' +Str_Path+'''');
DM.QSJBF.ExecSQL();
Screen.Cursor := crDefault;
Application.MessageBox('数据库备份成功完成','数据库备份',0+mb_iconinformation);
except
Screen.Cursor := crDefault;
Application.MessageBox('数据库备份失败!请检查备份路径或网络状态','数据库备份',0+mb_iconinformation);
exit;
end;
end;
end;
//数据恢复
var
Str_Path:string;
begin
DM.ADOConn.Close;
DM.ADOConn.Connected:=False;
Opendialog1.Filter := '所有文件(*.*)|*.*';
Opendialog1.Title := '选择恢复文件路径和文件名';
if Opendialog1.Execute then
Str_Path:=opendialog1.FileName;
if Str_Path<>'' then
begin
with DM.QSJHF do
begin
try
try
Screen.Cursor := crHourGlass;
Close;
SQL.Clear;
SQL.Add('use master restore DATABASE 物流管理系统 from DISK ='+'''' +Str_Path+'''');
ExecSQL();
Screen.Cursor := crDefault;
Application.MessageBox('数据库恢复成功完成!','数据库恢复',0+mb_iconinformation);
except
Screen.Cursor := crDefault;
Application.MessageBox('数据库恢复失败!请检查备份路径或网络状态','数据库恢复',0+mb_iconinformation);
exit;
end;
Finally
with DM.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('USE 物流管理系统');
ExecSQL;
end;
end;
end;
end;
DM.ADOConn.Open;
DM.ADOConn.Connected:=True;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls, ExtCtrls, DB, ADODB;
type
TForm1 = class(TForm)
Panel1: TPanel;
Label1: TLabel;
PB: TProgressBar;
StatusBar1: TStatusBar;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
ADOQuery1: TADOQuery;
ADOConnection1: TADOConnection;
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
dir:string;
id:DWORD;
pd:THandle;
implementation
{$R *.dfm}
procedure TForm1.BitBtn3Click(Sender: TObject);
begin
Close;
end;
function pro:Boolean;
begin
if Form1.PB.position<100 then
Form1.PB.Position:=Form1.PB.Position+1;
end;
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
try
if SaveDialog1.Execute then
begin
dir:=SaveDialog1.FileName+'.bak';
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Text:='backup database db_ems to disk='''+dir+'''';
ExecSQL;
end;
pd:=createthread(nil,0,@pro,nil,0,id);
PB.Position:=PB.Max;
ShowMessage('备份OK!');
PB.Position:=PB.Min;
end;
except
begin
ShowMessage('备份失败!');
PB.Position:=PB.Min;
end;
end;
end;
procedure TForm1.BitBtn2Click(Sender: TObject);
begin
try
if OpenDialog1.Execute then
begin
dir:=OpenDialog1.FileName;
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Text:='use master restore database db_EMS from disk='''+dir+'''';
ExecSQL;
end;
pd:=CreateThread(nil,0,@pro,nil,0,id);
PB.Position:=PB.Max;
ShowMessage('还原OK!');
PB.Position:=PB.Min;
end;
except
showmessage('还原失败!');
pb.Position:=PB.Min;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
postmessage(Pb.Handle,$0409,0,clLime);
end;
end.
这样还简单点,呵呵