请问:恢复数据库不出错,但是检查数据根本没有恢复?为什么?(帮忙看看) ( 积分: 100 )

  • 主题发起人 主题发起人 liubin44966
  • 开始时间 开始时间
L

liubin44966

Unregistered / Unconfirmed
GUEST, unregistred user!
dm.ADOConnection1//业务数据库连接
ADOConnection2//连接master 数据库
dm.ADOConnection1.Connected:=false;
ADOConnection2.Connected:=false;
ADOConnection2.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master; Data Source=aa';
ADOConnection2.Connected:=true;
adoquery1.connection:=ADOConnection2;
with adoquery1 do
begin
close;
sql.clear;
sql.add('USE master restore filelistonly from disk =''D:/tzsbgl(sql)/备份/特种设备数据 (2005-12-13).JA'' ')
sql.add('restore database tzsb' );
sql.add(' from disk =''D:/tzsbgl(sql)/备份/特种设备数据 (2005-12-13).JA'' ');
sql.add(' WITH move 'tzsb_Data' to ''D:/tzsbgl(sql)/tzsb_Data.MDF'' ');
sql.add(' , move 'tzsb_Log' to ''D:/tzsbgl(sql)/tzsb_Log.LDF'' ,replace');
try
ExecSQL;
Application.MessageBox('恭喜您恢复数据库成功!','提示',MB_OK+MB_ICONEXCLAMATION);
except
on E:Exception do
begin
Application.MessageBox(pchar(e.Message),'提示',MB_OK+MB_ICONEXCLAMATION);
exit;
end;
end;
end;
 
dm.ADOConnection1//业务数据库连接
ADOConnection2//连接master 数据库
dm.ADOConnection1.Connected:=false;
ADOConnection2.Connected:=false;
ADOConnection2.ConnectionString:='Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master; Data Source=aa';
ADOConnection2.Connected:=true;
adoquery1.connection:=ADOConnection2;
with adoquery1 do
begin
close;
sql.clear;
sql.add('USE master restore filelistonly from disk =''D:/tzsbgl(sql)/备份/特种设备数据 (2005-12-13).JA'' ')
sql.add('restore database tzsb' );
sql.add(' from disk =''D:/tzsbgl(sql)/备份/特种设备数据 (2005-12-13).JA'' ');
sql.add(' WITH move 'tzsb_Data' to ''D:/tzsbgl(sql)/tzsb_Data.MDF'' ');
sql.add(' , move 'tzsb_Log' to ''D:/tzsbgl(sql)/tzsb_Log.LDF'' ,replace');
try
ExecSQL;
Application.MessageBox('恭喜您恢复数据库成功!','提示',MB_OK+MB_ICONEXCLAMATION);
except
on E:Exception do
begin
Application.MessageBox(pchar(e.Message),'提示',MB_OK+MB_ICONEXCLAMATION);
exit;
end;
end;
end;
 
先杀进程,在恢复。
declare @spid varchar(20)
declare #spid cursor for
select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=数据库ID号
open #spid
fetch next from #spid into @spid
while @@fetch_status=0
begin
exec('kill '+@spid)
fetch next from #spid into @spid
end
close #spid
deallocate #spid
 
在sql语句之前加上这样的语句:ALTER OUTER BASE 数据库名 SET OFFLINE WITH ROLLBACK IMM EDIATE
之后加上:ALTER OUTER BASE 数据库名 SET OnLINE WITH ROLLBACK IMM EDIATE
 
多人接受答案了。
 
后退
顶部