为什么在VS.2008上C#用SQLEXPRESS在开发的机器上能正常从备份数据库中恢复数据库正常运行,而到目标机器上安装后就出现下列错误。见错误信息:

zcdg909 2009-03-13 11:15:26
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);

......................................
注:在目标机器上附加可以成功,没有问题。就是不能从备份数据库中恢复出两个数据库文件。在开发机器上两者都能。
...全文
49 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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