我的恢复是这么写的,但是当执行到‘*’号处就不行了,错误提示:无法重写文件
‘C:/Program Files/Microsoft SQL Server/MSSQL/data/Medicine_data.MDF'数据库
medicine正在使用该文件。我明明已经将它断开了,他怎么还说我在使用???迷惑
请各位高手帮着看看,到底哪里出了错
DM1.ADOConnection1.Connected:= False;
//连接到Master
DM1.ADOConnection1.ConnectionString:= 'Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=ZY;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=ZY;Use Encryption for Data=False;Tag with column collation when possible=False';
DM1.ADOConnection1.Connected:= True;
try
DM1.ADOCommand1.CommandText := 'ALTER DATABASE Medicine SET OFFLINE WITH ROLLBACK IMMEDIATE';
DM1.ADOCommand1.Execute;
if OpenDialog1.Execute
then DM1.ADOCommand1.CommandText := 'RESTORE DATABASE Med_Back FROM DISK = ''' + OpenDialog1.FileName + ''''//备份为数据库Med_Back,而非原数据库名medicine
else Exit;
[red]* [/red] DM1.ADOCommand1.Execute;
finally
DM1.ADOCommand1.CommandText := 'ALTER DATABASE Medicine SET ONLINE WITH ROLLBACK IMMEDIATE';
DM1.ADOCommand1.Execute;
DM1.ADOConnection1.Connected := True;
end;
DM1.ADOConnection1.Connected:= False;
//DM1.ADOConnection1.ConnectionString:= WideString('Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=medicine;Data Source=ZY;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=ZY;Use Encryption for Data=False;Tag with column collation when possible=False'
DM1.ADOConnection1.Connected:= True;