为何用数据库中的所有任务中的备份可以成功,而恢复却总是说设备错误?
如何在delphi的程序中通过restore恢复,我用restore时总说数据库正在运行
有何解决良策?请各位大虾指教一下
如何在delphi的程序中通过restore恢复,我用restore时总说数据库正在运行
有何解决良策?请各位大虾指教一下
解决方案 »
- delphi中TCollection是如何实现用下标存取TCollectionItem的
- 请问会员卡系统需要哪些硬件?
- TChart或者TDBChart的问题
- SOS!!!!!用过Ehlib的DBGridEh的请进!
- 有没有办法改变发信端口
- adoquery的filter中支不支持模糊查询?
- sos!!!計算字段值的更新問題
- 清家荡产SOS!,我能给的分就这些!求救在DELPHI中怎样动态更新和调用AcitiveX组件。
- QuickReport中的问题紧急求救,请各位大虾给予帮助
- QuickRep打印表格的线宽如何设?
- 如何列出sqlserver服务器上的数据库列表
- (SOS)我用NMFTP控件怎么只能下载,不能上传啊,在线急等
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;
csdn上有不少这样的帖子 你可以搜索看看 肯定对你是由帮助的
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;