我使用实体数据模型 (=.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/