+ -
当前位置:首页 → 问答吧 → Delphi中SQLSErver2000数据库备份还原

Delphi中SQLSErver2000数据库备份还原

时间:2011-12-19

来源:互联网

在Delphi写的程序中,增加功能,数据库备份、还原,在线备份没有问题,可是数据库还原后变为置疑,不能使用了,没有看出了哪里有问题,请高手帮忙看看。
还原的代码如下:
 AdoCnt.Close; //关闭原来的数据库连接
  if AdoCnt.Connected then  
  AdoCnt.Connected := False ;

  ADOBackup.ConnectionString := 'Provider=SQLOLEDB.1;Password='+EDIT5.TEXT+';Persist Security Info=True;User ID='+EDIT4.TEXT+';Initial Catalog=master;Data Source='+Edit3.TEXT+'';
  with ADOBackup do  
  begin
  ADOBackup.Close;
  SQL.Clear ;
  l_sql := 'use master alter database libary set offline WITH ROLLBACK IMMEDIATE ' +
  'restore database libary from disk=' + QuotedStr(Edit2.Text) + ' with REPLACE ' +
  'alter database libary set online with rollback immediate ' ;
  ADOBackUP.SQL.Text := l_sql;
   
  try
  AdoBackUp.ExecSQL ;  
  ShowMessage('恢复成功!');
  except
  ShowMessage('还原失败!');
  end;
  end;

作者: w001001001001   发布时间: 2011-12-19

在ShowMessage('恢复成功!');报错误 Project 'xxx.exe' raised exception class EDatabaseError with Message 'Missing Connection or ConnectionString'. Process stopped.Use Step or Run to continue.
这时间有不需要连接数据库,为什么会报这样的错误呢。

作者: w001001001001   发布时间: 2011-12-19