源码如下,可以正常还原.但无法指定还原后的数据库文件路径(如下注释所述).请问应该怎么实现呢function TdbmSQLDMO.RestoreDB(DBName, RestoreFile, DBFile: string): Boolean;
var SQLRestore: _Restore;
begin
Result := True;
try
SQLRestore := coRestore.Create;
except
TdbmCommon.MsgBox('还原对象无法创建,请检查是否安装SQLSERVER或MSDE引擎!');
Result := false;
Exit;
end;
with SQLRestore do
begin
try
Files := RestoreFile;
ReplaceDatabase := true;
Database := DBName;
//****************************
DatabaseFiles := DBFile; //希望能让用户指定还原后的数据库路径,可是这样不起任何作用
//******************************
SQLRestore(FSQLServer)
except
on E: Exception do
begin
TdbmCommon.MsgBox(E.Message);
Result := false;
end;
end;
end;end;
var SQLRestore: _Restore;
begin
Result := True;
try
SQLRestore := coRestore.Create;
except
TdbmCommon.MsgBox('还原对象无法创建,请检查是否安装SQLSERVER或MSDE引擎!');
Result := false;
Exit;
end;
with SQLRestore do
begin
try
Files := RestoreFile;
ReplaceDatabase := true;
Database := DBName;
//****************************
DatabaseFiles := DBFile; //希望能让用户指定还原后的数据库路径,可是这样不起任何作用
//******************************
SQLRestore(FSQLServer)
except
on E: Exception do
begin
TdbmCommon.MsgBox(E.Message);
Result := false;
end;
end;
end;end;
可是企业管理器都能实现这样的功能阿?
=============================
同意可以直接用语句来还原啊,何必那样
SQLRestore.RelocateFiles := '[graspcw_Data],[' + DBFile + '.mdf],[graspcw_Log],' +
'['+DBFile+'.ldf]';
用RelocateFiles完成数据库文件的移动。相当于下例中的 Move [] To []
RESTORE DATABASE MyNwind
FROM MyNwind_1
WITH NORECOVERY,
MOVE 'MyNwind' TO 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\NewNwind.mdf',
MOVE 'MyNwindLog1' TO 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\NewNwind.ldf'
RESTORE LOG MyNwind
FROM MyNwindLog1
WITH RECOVERY
RelocateFiles中参数必须要成对出现,前面为逻辑文件名,后面为数据地址。
还是感谢大家的参与,散分