关于SQL SERVER2000的数据备份,恢复问题?(在线等)

jihua163 2003-10-17 05:10:57
为何用数据库中的所有任务中的备份可以成功,而恢复却总是说设备错误?
如何在delphi的程序中通过restore恢复,我用restore时总说数据库正在运行
有何解决良策?请各位大虾指教一下
...全文
65 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
killer2008 2003-10-17
  • 打赏
  • 举报
回复
简单:
procedure TForm1.Button1Click(Sender: TObject);
var
query1:tadoquery;
restorepath,databasename:string;
begin
restorepath:='e:\yl';//备份文件
databasename:='mydata';
query1:=tadoquery.Create(nil);
try
with query1 do
Begin
Connection := adoconnection1;//adoconnection1不用连任何数据库
SQL.Add('Use Master');
SQL.Add('Restore DataBase ' + DataBaseName);
SQL.Add(' from disk = ' + '''' + RestorePath + '''');
SQL.Add('with recovery,Replace');
try
ExecSql;
except
end;
end;

finally
query1.Free;
end;
end;
angle097113 2003-10-17
  • 打赏
  • 举报
回复
数据库恢复的时候应该先把数据库断开
csdn上有不少这样的帖子 你可以搜索看看 肯定对你是由帮助的
Alanwn 2003-10-17
  • 打赏
  • 举报
回复
正在运行是你还没有关掉数据库啊!
function RestoreDataBase(var Conn:TADOConnection;
SourceFile:string;
MainSourceFile:string;
TargetPath:string;
BackupInfo:TBackupInfo):Integer;
var
AdoCmd : TADOCommand;
const
RestoreSQL = 'RESTORE DATABASE [%s] FROM DISK = %s WITH %s REPLACE,move %s to %s,move %s to %s';
CommonWord = 'recovery, ';
DeferentWord1 = 'FILE = 1,NORECOVERY, ';
DeferentWord2 = 'FILE = 1,RECOVERY, ';
begin
Screen.Cursor:=crhourGlass;
AdoCmd:=TADOCommand.Create(nil);
try
try
AdoCmd.Connection:=Conn;
if BackupInfo.BackupType = 0 then
begin
AdoCmd.CommandText:=format(RestoreSQL,
[BackupInfo.DBName,
QuotedStr(SourceFile),
CommonWord,
QuotedStr(BackupInfo.DataFile),
QuotedStr(TargetPath+BackupInfo.DataFile+'.mdf'),
QuotedStr(BackupInfo.LogFile),
QuotedStr(TargetPath+BackupInfo.LogFile+'.ldf')]);
AdoCmd.Execute;
end
else
begin
AdoCmd.CommandText:=format(RestoreSQL,
[BackupInfo.DBName,
QuotedStr(MainSourceFile),
DeferentWord1,
QuotedStr(BackupInfo.DataFile),
QuotedStr(TargetPath+BackupInfo.DataFile+'.mdf'),
QuotedStr(BackupInfo.LogFile),
QuotedStr(TargetPath+BackupInfo.LogFile+'.ldf')]
);
AdoCmd.Execute;
AdoCmd.CommandText:=format(RestoreSQL,
[BackupInfo.DBName,
QuotedStr(SourceFile),
DeferentWord2,
QuotedStr(BackupInfo.DataFile),
QuotedStr(TargetPath+BackupInfo.DataFile+'.mdf'),
QuotedStr(BackupInfo.LogFile),
QuotedStr(TargetPath+BackupInfo.LogFile+'.ldf')]);
AdoCmd.Execute;
end;
result:=0;
except
on E: Exception do
begin
Application.MessageBox(Pchar(E.Message),'提示信息',{ E.HelpContext,}MB_ICONError+mb_OK);
Result := -1;
end;
end;
finally
AdoCmd.Free;
Screen.Cursor:=crdefault;
end;
end;

2,495

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧