X
xuefeiyang
Unregistered / Unconfirmed
GUEST, unregistred user!
try
DM.ADOConnection1.Connected:=False;//关闭sbhy数据库
DM.adocommand1.Connection:=DM.ADOConnection2;//转移连接到数据库master
DM.ADOCommand1.CommandText:='ALTER DATABASE sbhy SET OFFLINE WITH ROLLBACK IMMEDIATE';//切断sbhy连接
DM.ADOCommand1.Execute;
DM.ADOCommand1.CommandText:='RESTORE DATABASE sbhy FROM DISK = ''' +opendialog1.FileName +'''';//恢复sbhy数据库
DM.ADOCommand1.Execute;
showmessage('完成');
finally
DM.ADOCommand1.CommandText:='ALTER DATABASE sbhy SET ONLINE WITH ROLLBACK IMMEDIATE';//重新连接sbhy数据库
DM.ADOCommand1.Execute;
DM.ADOConnection2.Connected:=False;//关闭master数据库
end;
DM.ADOConnection1.Connected:=True;//打开sbhy数据库
DM.adocommand1.Connection:=DM.ADOConnection1;//恢复连接到数据库sbhy
DM.ADOConnection1.Connected:=False;//关闭sbhy数据库
DM.adocommand1.Connection:=DM.ADOConnection2;//转移连接到数据库master
DM.ADOCommand1.CommandText:='ALTER DATABASE sbhy SET OFFLINE WITH ROLLBACK IMMEDIATE';//切断sbhy连接
DM.ADOCommand1.Execute;
DM.ADOCommand1.CommandText:='RESTORE DATABASE sbhy FROM DISK = ''' +opendialog1.FileName +'''';//恢复sbhy数据库
DM.ADOCommand1.Execute;
showmessage('完成');
finally
DM.ADOCommand1.CommandText:='ALTER DATABASE sbhy SET ONLINE WITH ROLLBACK IMMEDIATE';//重新连接sbhy数据库
DM.ADOCommand1.Execute;
DM.ADOConnection2.Connected:=False;//关闭master数据库
end;
DM.ADOConnection1.Connected:=True;//打开sbhy数据库
DM.adocommand1.Connection:=DM.ADOConnection1;//恢复连接到数据库sbhy