procedure TMainForm.N6Click(Sender: TObject);
var
filePath: string;
begin
if BackupDialog.Execute then
begin
filePath := BackupDialog.FileName;
end;
if length (filePath) < 4 then exit; if Ado_Backup.Active then Ado_Backup.Close;
Ado_Backup.SQL.Clear; Ado_Backup.SQL.Add('RESTORE DATABASE hxxt from disk = ' +
'''' + filePath + '''');
//dm.ADOConnection1.Close; *******************
//dm.Free; ********************
try
Ado_Backup.ExecSQL;
except
MessageDlg('数据恢复不成功!', mtInformation, [mbOK], 0);
exit;
end;
MessageDlg('数据恢复成功!', mtInformation, [mbOK], 0);
end;我在使用上面的语句还原的时候,说什么 database in use 不能还原,
我加上带"***"的两句,又说什么no database connection. 不能还原,气死了!
谁告诉我到底是怎么回事呀!!!
var
filePath: string;
begin
if BackupDialog.Execute then
begin
filePath := BackupDialog.FileName;
end;
if length (filePath) < 4 then exit; if Ado_Backup.Active then Ado_Backup.Close;
Ado_Backup.SQL.Clear; Ado_Backup.SQL.Add('RESTORE DATABASE hxxt from disk = ' +
'''' + filePath + '''');
//dm.ADOConnection1.Close; *******************
//dm.Free; ********************
try
Ado_Backup.ExecSQL;
except
MessageDlg('数据恢复不成功!', mtInformation, [mbOK], 0);
exit;
end;
MessageDlg('数据恢复成功!', mtInformation, [mbOK], 0);
end;我在使用上面的语句还原的时候,说什么 database in use 不能还原,
我加上带"***"的两句,又说什么no database connection. 不能还原,气死了!
谁告诉我到底是怎么回事呀!!!
use master
go
create proc killspid (@dbname varchar(20))
as
begin
declare @sql nvarchar(500),@temp varchar(1000)
declare @spid int
set @sql='declare getspid cursor for
select spid from sysprocesses where dbid=db_id('''+@dbname+''')'
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status=0
begin
set @temp='kill '+rtrim(@spid)
exec(@temp)
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end use master
exec killspid 'youdb'我老用这个骗分的,给分吧
begin
filePath := BackupDialog.FileName;
end;
if length (filePath) < 4 then exit; if Ado_Backup.Active then Ado_Backup.Close;
Ado_Backup.SQL.Clear; Ado_Backup.SQL.Add('RESTORE DATABASE hxxt from disk = ' +
'''' + filePath + '''');
try
if not dm.ADOConnection1.Active then
dm.ADOConnection1.Active := true; //////////// *******************
Ado_Backup.ExecSQL;
except
MessageDlg('数据恢复不成功!', mtInformation, [mbOK], 0);
exit;
end;
MessageDlg('数据恢复成功!', mtInformation, [mbOK], 0);
是不能先关闭和释放的。执行完以后再关闭和释放。
var
filePath: string;
begin
if BackupDialog.Execute then
begin
filePath := BackupDialog.FileName;
end;
if length (filePath) < 4 then exit; if Ado_Backup.Active then Ado_Backup.Close;
Ado_Backup.SQL.Clear; Ado_Backup.SQL.Add('use master RESTORE DATABASE hxxt from disk = ' +
'''' + filePath + '''');
//dm.ADOConnection1.Close; *******************
//dm.Free; ********************
try
Ado_Backup.ExecSQL;
except
MessageDlg('数据恢复不成功!', mtInformation, [mbOK], 0);
exit;
end;
MessageDlg('数据恢复成功!', mtInformation, [mbOK], 0);
end;
当然,首先要保证没有其它的连接在要还原的数据库上
还原数据库的时候不要有去连接你所要还原的数据库~~~~
比如~我们要还原~!MyDatabase数据库~~~在用ADOTable连接数据库的时候不要选择MyDatabase~可以连接上Master数据库~~然后
RESTORE DATABASE [MyDatabase] FROM DISK = 'X:\MyDatabase.bak'