delphi 中 如何实现对sql-server 数据库的备份恢复 在delphi中选何组件,语句如何写?拜托!我给100分 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 procedure TDBBackupForm.XP_Button2Click(Sender: TObject);begin pgbar.Max:=100; pgbar.Min:=0; pgbar.Position:=0; pgbar.Step:=20; With SaveDialog1 do begin filename:='DB'+FormatDateTime('yy_MM_dd_hh_mm_ss',Now); options:=[ofhidereadonly,offilemustexist,ofpathmustexist]; if execute then begin label1.Caption:='正在备份中...'; DataModule1.ADOConnection1.Close; TmpStr:= ExtractFileName(filename); strlen:= Length(TmpStr); DevName:= Copy(TmpStr,1,strlen-4); begin try ADOCommand1.CommandText:='use Master'; pgbar.StepIt; ADOCommand1.Execute; adocommand1.CommandText:='execute sp_helpdevice'; pgbar.StepIt; adocommand1.Execute ; pgbar.stepit; adocommand1.CommandText:='backup database '+InitDB+' to disk='''+filename+''' with init'; pgbar.StepIt; adocommand1.Execute ; adocommand1.CommandText:='Use '+InitDB; pgbar.StepIt; adocommand1.Execute ; Self.Hide; ShowMessage('数据库已经成功备份到 '+filename+'!'); Try DataModule1.ADOConnection1.Connected:= True; Except ShowMessage('无法重新接连数据库!,系统即将退出!'); Application.Terminate; End; self.Close; Except On Exception do if DataModule1.ADOConnection1.InTransaction then DataModule1.ADOConnection1.RollbackTrans; End; End; end; end;end;procedure TDBBackupForm.FormActivate(Sender: TObject);begin SYSINI := TIniFile.Create(ExtractFilePath(Application.ExeName)+'DB.INI'); try InitDB := SYSINI.ReadString('Database', 'InitDB', ''); finally SYSINI.Free; end;end;procedure TDBBackupForm.XP_Button3Click(Sender: TObject);begin pgbar.Max:=100; pgbar.Min:=0; pgbar.Position:=0; pgbar.Step:=20; With OpenDialog1 do begin filename:=''; options:=[ofhidereadonly,offilemustexist,ofpathmustexist]; if execute then begin label1.Caption:='正在还原中...'; DataModule1.ADOConnection1.Close; TmpStr:= ExtractFileName(filename); strlen:= Length(TmpStr); DevName:= Copy(TmpStr,1,strlen-4); pgbar.StepIt; try ADOCommand1.CommandText:='use Master'; ADOCommand1.Execute; pgbar.StepIt; adocommand1.CommandText:='execute sp_helpdevice'; adocommand1.Execute ; pgbar.stepit; adocommand1.CommandText:='Restore database '+InitDB+' From disk='''+filename+''' with replace'; pgbar.StepIt; adocommand1.Execute ; adocommand1.CommandText:='Use '+InitDB; pgbar.StepIt; adocommand1.Execute ; Self.Hide; ShowMessage('数据库已经成功还原到数据库 '+InitDB+'!'); Try DataModule1.ADOConnection1.Connected:= True; Except ShowMessage('无法重新接连数据库!,系统即将退出!'); Application.Terminate; End; self.Close; Except On Exception do if DataModule1.ADOConnection1.InTransaction then DataModule1.ADOConnection1.RollbackTrans; End; end; end;end; 请推荐个好的控件 如何获取dll中按钮的click事件 即使没有WIN32下新的DELPHI版本,我认为DELPHI依然兴旺很长一段时间。 用apro在两台电脑上传送数据 如何创建含有childform的dll,并调用?调用时,如何找父窗体? 关于类的编写 怎样得到SQLServer服务器下的所有数据库名? 用Delphi来开发MIS系统的问题,欢迎作答。 热烈庆祝华东交大建校三十周年,交大的同学请进来! 收集意见,Delphi7应该有哪些改进? 如何把这样的字符转成数字,然后再转回来,急,菜鸟求救 问一个关于DELPHI 7 问题!(有关界面)
begin
pgbar.Max:=100;
pgbar.Min:=0;
pgbar.Position:=0;
pgbar.Step:=20;
With SaveDialog1 do
begin
filename:='DB'+FormatDateTime('yy_MM_dd_hh_mm_ss',Now);
options:=[ofhidereadonly,offilemustexist,ofpathmustexist];
if execute then
begin
label1.Caption:='正在备份中...';
DataModule1.ADOConnection1.Close;
TmpStr:= ExtractFileName(filename);
strlen:= Length(TmpStr);
DevName:= Copy(TmpStr,1,strlen-4);
begin
try
ADOCommand1.CommandText:='use Master';
pgbar.StepIt;
ADOCommand1.Execute;
adocommand1.CommandText:='execute sp_helpdevice';
pgbar.StepIt;
adocommand1.Execute ;
pgbar.stepit;
adocommand1.CommandText:='backup database '+InitDB+' to disk='''+filename+''' with init';
pgbar.StepIt;
adocommand1.Execute ;
adocommand1.CommandText:='Use '+InitDB;
pgbar.StepIt;
adocommand1.Execute ;
Self.Hide;
ShowMessage('数据库已经成功备份到 '+filename+'!');
Try
DataModule1.ADOConnection1.Connected:= True;
Except
ShowMessage('无法重新接连数据库!,系统即将退出!');
Application.Terminate;
End;
self.Close;
Except
On Exception do
if DataModule1.ADOConnection1.InTransaction then
DataModule1.ADOConnection1.RollbackTrans;
End;
End;
end;
end;end;procedure TDBBackupForm.FormActivate(Sender: TObject);
begin
SYSINI := TIniFile.Create(ExtractFilePath(Application.ExeName)+'DB.INI');
try
InitDB := SYSINI.ReadString('Database', 'InitDB', '');
finally
SYSINI.Free;
end;end;procedure TDBBackupForm.XP_Button3Click(Sender: TObject);
begin
pgbar.Max:=100;
pgbar.Min:=0;
pgbar.Position:=0;
pgbar.Step:=20;
With OpenDialog1 do
begin
filename:='';
options:=[ofhidereadonly,offilemustexist,ofpathmustexist];
if execute then
begin
label1.Caption:='正在还原中...';
DataModule1.ADOConnection1.Close;
TmpStr:= ExtractFileName(filename);
strlen:= Length(TmpStr);
DevName:= Copy(TmpStr,1,strlen-4);
pgbar.StepIt;
try
ADOCommand1.CommandText:='use Master';
ADOCommand1.Execute;
pgbar.StepIt;
adocommand1.CommandText:='execute sp_helpdevice';
adocommand1.Execute ;
pgbar.stepit;
adocommand1.CommandText:='Restore database '+InitDB+' From disk='''+filename+''' with replace';
pgbar.StepIt;
adocommand1.Execute ;
adocommand1.CommandText:='Use '+InitDB;
pgbar.StepIt;
adocommand1.Execute ;
Self.Hide;
ShowMessage('数据库已经成功还原到数据库 '+InitDB+'!');
Try
DataModule1.ADOConnection1.Connected:= True;
Except
ShowMessage('无法重新接连数据库!,系统即将退出!');
Application.Terminate;
End;
self.Close;
Except
On Exception do
if DataModule1.ADOConnection1.InTransaction then
DataModule1.ADOConnection1.RollbackTrans;
End;
end;
end;end;