c# - 实体框架无法创建数据库(操作系统错误 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 共享上。
在同一行
安装上次累积更新没有帮助
解决方案
推荐阅读
- javascript - 推送被拒绝,无法编译 Node.js 应用程序。尝试了本网站上发布的许多不同的东西
- php - PHP在文本文件上的特定行之后计算行
- excel - 我可以修改此宏以仅在一列上运行吗?
- flutter - Restarting WebP animation to first frame in Flutter
- ruby-on-rails - 如何在活动记录中获取保存的数据库对象?
- javascript - 如何在反应输入组件中制作基于黑名单的过滤器
- vue.js - 使用 vm.$once() 时,Vue 应用程序如何将附加参数传递给事件侦听器?
- android - Android Material Calendar View如何用圆角背景突出显示日期范围?
- assembly - 如何编写汇编语言使 DMA 工作
- python - 分配给 numpy 结构化数组