G
guorui7832
Unregistered / Unconfirmed
GUEST, unregistred user!
请教一个问题:
现有两台机器,一台机器(1)中安装了sql数据库服务器,有sql数据库信息,在另一台机器(2)中运行delphi开发备份程序,将机器(1)中的sql数据库信息备份到机器(2)中代码如何实现?
我写了一段代码,是在机器(1)中运行能够备份保存,在机器(2)中运行程序后,备份数据放到(1)中了。可以需要改进一下,请教各位!!代码如下:
procedure Tdsjbff1.FormCreate(Sender: TObject);
var kpath,kdir:string;
begin
Icmp.Host:=192.168.1.2'; //判断网络是否正常
Icmp.ReceiveTimeout:=6000;
Icmp.Port:=1433;
Icmp.Ping();
if Icmp.ReplyStatus.BytesReceived > 0 then
try
begin
mm_cnt:='Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Initial Catalog=ppxt;Data Source=192.168.1.2';
ADOConnection1.ConnectionString:=mm_cnt;
ADOConnection1.Connected:=true;
ADOConnection1.KeepConnection:=true;
with Query1 do
begin
close;
sql.Clear;
sql.Add('select getdate() as getdate ') ;
open;
kpath:='C:/数据备份';
if not DirectoryExists(kpath) then MkDir(kpath);
kdir:=kpath+'/'+formatdatetime('yyyymmdd',fieldbyname('getdate').AsDateTime-60)+'.back';
if FileExists(kdir) then DeleteFile(kdir);
kdir:=kpath+'/'+formatdatetime('yyyymmdd',fieldbyname('getdate').AsDateTime)+'.back';
if FileExists(kdir) then DeleteFile(kdir);
Close;
SQL.Clear;
SQL.Add('backup database ddxt to disk='''+kdir+'''');
ExecSQL;
end;
ShowMessage('备份成功!');
Application.Terminate;
end;
except
begin
showmessage('网络连接出现问题,数据没有备份?');
Application.Terminate;
end;
end
else
begin
showmessage('网络连接出现问题,数据没有备份?');
Application.Terminate;
end;
end;
现有两台机器,一台机器(1)中安装了sql数据库服务器,有sql数据库信息,在另一台机器(2)中运行delphi开发备份程序,将机器(1)中的sql数据库信息备份到机器(2)中代码如何实现?
我写了一段代码,是在机器(1)中运行能够备份保存,在机器(2)中运行程序后,备份数据放到(1)中了。可以需要改进一下,请教各位!!代码如下:
procedure Tdsjbff1.FormCreate(Sender: TObject);
var kpath,kdir:string;
begin
Icmp.Host:=192.168.1.2'; //判断网络是否正常
Icmp.ReceiveTimeout:=6000;
Icmp.Port:=1433;
Icmp.Ping();
if Icmp.ReplyStatus.BytesReceived > 0 then
try
begin
mm_cnt:='Provider=SQLOLEDB.1;Persist Security Info=True;User ID=sa;Initial Catalog=ppxt;Data Source=192.168.1.2';
ADOConnection1.ConnectionString:=mm_cnt;
ADOConnection1.Connected:=true;
ADOConnection1.KeepConnection:=true;
with Query1 do
begin
close;
sql.Clear;
sql.Add('select getdate() as getdate ') ;
open;
kpath:='C:/数据备份';
if not DirectoryExists(kpath) then MkDir(kpath);
kdir:=kpath+'/'+formatdatetime('yyyymmdd',fieldbyname('getdate').AsDateTime-60)+'.back';
if FileExists(kdir) then DeleteFile(kdir);
kdir:=kpath+'/'+formatdatetime('yyyymmdd',fieldbyname('getdate').AsDateTime)+'.back';
if FileExists(kdir) then DeleteFile(kdir);
Close;
SQL.Clear;
SQL.Add('backup database ddxt to disk='''+kdir+'''');
ExecSQL;
end;
ShowMessage('备份成功!');
Application.Terminate;
end;
except
begin
showmessage('网络连接出现问题,数据没有备份?');
Application.Terminate;
end;
end
else
begin
showmessage('网络连接出现问题,数据没有备份?');
Application.Terminate;
end;
end;