c# - 存在同名数据库,或无法打开指定文件,或位于 UNC 共享上。这是什么意思?

标签 c# asp.net database entity-framework

我使用实体数据模型 (=.edmx) 的 PL、BL、DAl、BE 构建了一个 ASP.NET 项目,该模型是从位于我的 DAL 项目中的基于服务的数据库 (=.mdf) 生成的。

我确实将 connectionString 从 BE app.config 复制到 PL web.config

怎么了?为什么我会收到此错误:

System.Data.SqlClient.SqlException: An attempt to attach an auto-named database for file C:\Documents and Settings\user\שולחן העבודה\למידה אישית\Lev\Lev\App_Data\Midrasha.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.

我的代码逻辑是 PL->BL->DAL-> 尝试将新对象保存到数据库中。 产生问题的代码行是:

public void AddFeedback(Feedback feed)
{
    MidrashaEntities _context = new MidrashaEntities();
    _context.Feedback.AddObject(feed);
    _context.SaveChanges();  <-------throw the exception
}

Feedback 是我 DAL 的 SQL 中的一个表,我将其生成为对象实体。

最佳答案

我在连接字符串之前遇到了同样的错误,所以确保你有正确的连接字符串

关于c# - 存在同名数据库,或无法打开指定文件,或位于 UNC 共享上。这是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8978367/

相关文章:

mysql - 简单订票系统DB设计的几点建议

mysql - ON CASCADE DELETE 实现

c# - XAML 如何设置复选框的框颜色样式?

c# - 'System.Management.Automation.Runspaces.InitialSessionState' 的类型初始值设定项抛出异常

c# - 如何将 mvc 数据注释与自动生成的 linqtosql 类结合使用

c# - 在 For 循环中使用 DateTime,递增日期不起作用

asp.net - 比较2个linq应用程序: Unexpected result

sql - 改进 SQL DateTime 的工作

c# - 以编程方式最小化 UWP

c# - 如何使用 lambda 表达式进行验证以验证某个小时是否为某个 "type"(必须为 hh :00 or hh:30)