解决:Unable to open the physical file "…….ldf". Operating system error 5: "5(拒绝访问。)".
使用IIS发布网站后,用浏览器访问涉及到与系统自动生成的数据库ASPNETDB.MDF交互的页面时,弹出以下错误:
Unable to open the physical file "E:\Asp.NET\MyWebsite\App_Data\aspnetdb_log.ldf". Operating system error 5: "5(拒绝访问。)".
An attempt to attach an auto-named database for file E:\Asp.NET\MyWebsite\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.SqlClient.SqlException: Unable to open the physical file "E:\Asp.NET\MyWebsite\App_Data\aspnetdb_log.ldf". Operating system error 5: "5(拒绝访问。)".
An attempt to attach an auto-named database for file E:\Asp.NET\MyWebsite\App_Data\aspnetdb.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
源错误:
行 64: public virtual System.Collections.ArrayList ProId {
行 65: get {
行 66: return ((System.Collections.ArrayList)(this.GetPropertyValue("ProId")));
行 67: }
行 68: set {
|
源文件: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\1dab7029\5fc82d96\App_Code.fxbt3ib8.1.cs
行: 66
在网上搜了很长时间,有网友认为是网站的路径问题。我的网站目录放在E盘,使用IIS默认网站的路径指向这个站点,但IIS只对C盘有所有控制权限,所以访问时会出现这样的错误。我将网站复制到C盘Intput目录后,将默认网站的路径改为C盘下的网站,再重新访问,这个错误就没有出现了。
这个问题解决后,又出现了另一个错误Failed to update database "C:\INETPUB\MySite\APP_DATA\ASPNETDB.MDF" because the database is read-only.又去搜了半天,终于解决了,原来是App_Data文件夹的权限问题,解决方法参考我的上一篇博文:http://blog.csdn.net/yangsai2010/article/details/8961651