实体异常:基础提供程序无法打开 [英] Entity Exception : the underlying provider failed to open

查看:83
本文介绍了实体异常:基础提供程序无法打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iv'e获得了一个在IIS7上托管服务的wcf服务主机,

iv'e got a wcf service host hosting a service on IIS7,

iv'e在其App_Data文件夹中添加了一个数据库,

iv'e added a database to it's App_Data folder ,

该服务引用到DAL项目

the service is referenced to a DAL project

包含从我的数据库生成的Entity Framework模型(来自WCF服务主机的数据库)

which holds an Entity Framework model generated from my DB ( The DB from the WCF Service Host )

我通过以下内部消息不断获得上述实体异常:

i keep getting the above entity exception with this inner message :

{"An attempt to attach an auto-named database for file C:\\Users\\eranot65\\Documents\\Visual Studio 2010\\Projects\\CustomsManager\\WcfManagerServiceHost\\App_Data\\CustomesDB.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."}

iv'e复制了连接字符串f从DAL / app.config到WcfManagerServiceHost / Web.config

iv'e copied the connection string from DAL/app.config to WcfManagerServiceHost/Web.config

   add name="CustomesDBEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string='Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Users\eranot65\Documents\Visual Studio 2010\Projects\CustomsManager\WcfManagerServiceHost\App_Data\CustomesDB.mdf";Integrated Security=True;Connect Timeout=30;User Instance=True;MultipleActiveResultSets=True'" providerName="System.Data.EntityClient"      

this当我尝试使用数据源实体模型时发生这种情况:

this happens when i try to use my data source entity model:

   public List<Employee> GetEmployees()
    {
        List<Employee> employees = null;
        using (CustomesDBEntities entites = new CustomesDBEntities())
        {
            employees = entites.Employees.ToList<Employee>();
        }
        return employees;
    }

在其他地方似乎并没有使用数据库,

it doesn't seem as if the DB is in use some where else ,

(1)如何检查其他进程是否正在握住数据库句柄?

(1) how can i check if some other process is holding a handle to my DB ?

( 2)在想法上会发生这种情况?

(2) in ideas this happens ?

推荐答案

我会考虑检查以下两件事之一:

I would consider checking one of two things:


  1. 在VS服务器资源管理器中或使用SQL Management Studio创建与SQL Express的连接,并确认您没有该名称的数据库

  1. Create a connection to your SQL Express, either in VS server explorer, or by using the SQL management studio, and verify you do not already have a database by that name attached to your server.

将您的项目从当前位置移动到磁盘上与用户无关的位置(这意味着不在桌面,文档等上) ..),例如-c:\temp,c:\projects ...原因是您正在运行Web应用程序,并且如果您在IIS中运行它,则工作进程的标识为除您之外的特殊身份,它可能无权访问数据库文件,因为位于您用户的私人文件夹中

Move your project from it's current location to somewhere on the disk which is not user-specific (meaning not on the desktop, documents etc..), for example - c:\temp, c:\projects... The reason for that is that you are running a web application, and in case you run it in IIS, the identity of the worker process is a special identity other than yours which might not have permissions to access the database file since it is located in a private folder of your user

这篇关于实体异常:基础提供程序无法打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆