源码:
datamodule1.adoconnection1.close;
datamodule1.adoconnection2.connectionstring:='provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security info=false;initial catalog=master;data source=数据库名';
with datamodule1.SQLCOMMAND DO
begin
sql.clear;
sql.add('restore database "价格管理" from disk='''+trim(edit1.text)+''' with replace');
open;
错误提示:因为数据库正在使用,所以未能获得对数据库的排它访问权.
请帮助.
在这里非常感谢各位给我上一个问题给予的帮助,thank you very much!
datamodule1.adoconnection1.close;
datamodule1.adoconnection2.connectionstring:='provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security info=false;initial catalog=master;data source=数据库名';
with datamodule1.SQLCOMMAND DO
begin
sql.clear;
sql.add('restore database "价格管理" from disk='''+trim(edit1.text)+''' with replace');
open;
错误提示:因为数据库正在使用,所以未能获得对数据库的排它访问权.
请帮助.
在这里非常感谢各位给我上一个问题给予的帮助,thank you very much!
我用的上面这个,是不是能断开,adoconnection2只是用在这里
adoquery1.SQL.Clear;
adoquery1.SQL.Text:='ALTER DATABASE 数据库名 SET OFFLINE WITH ROLLBACK IMMEDIATE';
//断开数据库连接';
adoquery1.ExecSQL;
然后在恢复
看行不
with QueryRestor do
begin
Close;
SQL.Clear;
SQL.Text := MySQL;
try
ExecSQL;
except
Application.MessageBox('关闭数据库出错!','错误!',mb_ok+mb_iconError);
end;
end;
RestorStr := 'RESTORE DATABASE Station_Monthticket FROM DISK = ''' + DataPath+ ''' WITH REPLACE';
with QueryRestor do
begin
Close;
SQL.Clear;
SQL.Text := RestorStr;
try
ExecSQL;
Application.MessageBox('恢复数据库成功!','提示!',mb_ok+mb_iconinformation);
a1.Active:=false;
self.Caption:=application.Title+'-备份与恢复';
except
Application.MessageBox('恢复数据库出错!','错误!',mb_ok+mb_iconError);
end;
end;
MySQL := 'ALTER DATABASE Station_Monthticket SET ONLINE WITH ROLLBACK IMMEDIATE';
with QueryRestor do
begin
Close;
SQL.Clear;
SQL.Text := MySQL;
try
ExecSQL;
except
Application.MessageBox('打开数据库出错!','错误!',mb_ok+mb_iconError);
end;
end;
DM.Sta_MonthTicketDB.Connected := True;
然后;ShellExecute(Handle,'open','restore.exe',nil,nil,SW_SHOWNORMAL);来运行
procedure TForm23.Button2Click(Sender: TObject);
begin
adoquery1.SQL.Clear;
adoquery1.SQL.Add('use Master');
adoquery1.ExecSQL;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('execute sp_helpdevice');
adoquery1.ExecSQL;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('Restore database "价格管理" From disk='''+trim(edit1.text)++'''');
adoquery1.ExecSQL;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('Use "价格管理"');
adoquery1.ExecSQL;
application.MessageBox('数据库完成恢复','警告',MB_OK);
end;