为什么在VS.2008上C#用SQLEXPRESS在开发的机器上能正常从备份数据库中恢复数据库正常运行,而到目标机器上安装后就出现下列错误。见错误信息:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.Data.SqlClient.SqlException: The operating system returned the error '5(拒绝访问。)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'C:\Program Files\ldcmm\Test1\TestDB.mdf'.
File 'LDCmmED_dat' cannot be restored to 'C:\Program Files\ldcmm\Test1\TestDB.mdf'. Use WITH MOVE to identify a valid location for the file.
The operating system returned the error '5(拒绝访问。)' while attempting 'RestoreContainer::ValidateTargetForCreation' on 'C:\Program Files\ldcmm\Test1\LDCmmED_log.ldf'.
File 'LDCmmED_log' cannot be restored to 'C:\Program Files\ldcmm\Test1\LDCmmED_log.ldf'. Use WITH MOVE to identify a valid location for the file.
Problems were identified while planning for the RESTORE statement. Previous messages provide details.
RESTORE DATABASE is terminating abnormally.
在开发机器上,下述代码运行正常:
string strSQL =
@"RESTORE DATABASE {0} FROM DISK ='{1}'
With Move '{0}_dat' to '{2}\{0}.mdf',
Move '{0}_log' to '{2}\{0}_log.ldf' ";
strSQL = string.Format(strSQL, dbName, bdBakPathFileName, dbPath);
......................................
注:在目标机器上附加可以成功,没有问题。就是不能从备份数据库中恢复出两个数据库文件。在开发机器上两者都能。