首页 > 解决方案 > 实体框架无法创建数据库(操作系统错误 5:“5(访问被拒绝。)”)

问题描述

VS 2017

ASP.NET MVC 5 空项目

实体框架 6

SQL Server 速成版 2017

项目位于 c:\users\user\source\repos\project

代码优先

web.config 中的连接字符串:

<add name="IdentityDb" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLExpress;AttachDbFilename=|DataDirectory|\IdentityDb2.mdf;Integrated Security=True" />

然后改为:

<add name="IdentityDb" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLExpress;AttachDbFilename=C:\Users\Public\Documents\IdentityDb2.mdf;Integrated Security=True" />

在第一种情况下出现错误

文件“C:\Users\user\source\repos\WebApplication3\WebApplication3\App_Data\IdentityDb2.mdf”的目录查找失败,出现操作系统错误 5(拒绝访问。)。创建数据库失败。无法创建列出的某些文件名。检查相关错误。

在线的

IdentityResult result = await UserManager.CreateAsync(user, model.Password);

在第二种情况下

无法打开物理文件“C:\Users\Public\Documents\IdentityDb2.mdf”。操作系统错误 5:“5(拒绝访问。)”。尝试为文件 C:\Users\Public\Documents\IdentityDb2.mdf 附加自动命名数据库失败。存在同名数据库,或无法打开指定文件,或位于 UNC 共享上。

在同一行

安装上次累积更新没有帮助

标签: c#asp.netsql-servervisual-studioentity-framework

解决方案


推荐阅读