S:='RESTORE DATABASE ['+DBName+
'] FROM DISK = N'''+filename+''' WITH FILE = 1, NOUNLOAD , STATS = 10, RECOVERY , REPLACE ';
for I:=0 to Application.ComponentCount-1 do
Begin
if Components is TAdoDataSet then
TAdoDataSet(Components).Close;
if Components is TADOQuery then
TADOQuery(Components).Close;
if Components is TADOTable then
TADOTable(Components).Close;
end;
ADOConnection1.Close;
ADOConnection1.ConnectionString:='Provider=SQLOLEDB.1;Password='
+G_DBServerPsw+';Persist Security Info=True;User ID='
+G_DBServerUser+';Initial Catalog=master;Data Source='
+G_ComputerName;
ADOConnection1.Connected:=True;
ADOQuery1.Close;
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add('sp_who');
ADOQuery1.Open ;
ADOQuery1.Filter :='dbname='''+AccountVar.DataBaseName+''' ';
ADOQuery1.Filtered :=true;
ADOQuery1.First ;
while not ADOQuery1.Eof do
begin
ADOCommand1.CommandText:='kill '+ADOQuery1.FieldByName('spid').AsString;
try //使用错误处理是因为在kill时链接可能已经断开了
ADOCommand1.Execute ; //kill 其它连接
except
end;
ADOQuery1.Next ;
end;
ADOQuery1.Close ;
ADOQuery1.SQL.Clear ;
ADOQuery1.SQL.Add(S);//restore语句
try
Screen.Cursor:=crSQLWait;
ADOQuery1.ExecSQL ;
MessageBox(Handle,'恢复成功!','信息',MB_OK+MB_ICONINFORMATION);
finally
Screen.Cursor:=crDefault;
G_CloseDirect:=True;
end;