备份SQL Server2000的数据库成功,但恢复时却失败,提示说我正在使用中,怎办?
我通过ADO进行的SQL语句备份SQL Server2000的数据库成功,但恢复时却失败,提示说我正在使用中,怎样解决?
if OpenDialog1.Execute then
begin
//DataBase1.Close;
DataBase1.Connected := False;
DataBase1.Params.Clear;
DataBase1.AliasName := 'master';
DataBase1.DatabaseName := 'master';
DataBase1.Params.Add('User Name=sa');
DataBase1.Connected := True;
Query1.DatabaseName := 'master';
try
with Query1 do
begin
Close;
UnPrePare;
SQL.Clear;
SQL.Add('Restore DataBase tsg from disk = :disk');
Params[0].AsString := OpenDialog1.FileName;
PrePare;
ExecSQL;
end;
except
ShowMessage('恢复失败');
Exit;
end;
end;
Application.MessageBox('恭喜您,数据恢复成功','提示',MB_OK + MB_ICONINFORMATION);
end;
你将BDE换成ADO就可以了;
另外用一个adoconnection连接master数据库,将原来的连接断开。然后使用Query连接这个Adoconnection使用Sql语句恢复
if RestorDialog.Execute then
begin
with TAdoQuery.Create(nil) do
try
close;
sql.Clear ;
FrmSystemDM.ADOConnection1.Connected := False;
Connection :=FrmSystemDM.ADOConnection2;
FrmSystemDM.ADOConnection2.Connected := True;
SQL.add(Format('Restore DATABASE DHPrint From DISK=''%s'' with Replace', [RestorDialog.FileName]));
ExecSQL ;
finally
FrmSystemDM.ADOConnection1.Connected := True;
FrmSystemDM.ADOConnection2.Connected := False;
free;
end;
end;
end;