实体框架提供的异常:"底层提供程序未能在开放和QUOT;。 [英] Entity Framework giving exception : "The underlying provider failed on Open."

查看:187
本文介绍了实体框架提供的异常:"底层提供程序未能在开放和QUOT;。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个测试。什么情况是,每当test1的第一次执行,test2的失败,与消息:

I have a test. What happens is that whenever test1 is executed first, test2 fails with the message:

System.Data.EntityException:System.Data.EntityException:       潜在的供应商未能开放。无法打开数据库        由登录请求DBEntities。登录失败。

"System.Data.EntityException : System.Data.EntityException : the underlying provider failed on open. cannot open database "DBEntities" requested by the login. The login failed.".

和TEST2时首先执行,test1的失败,同样的信息。

and whenever test2 is executed first, test1 fails with the same message.

我已经在这个在过去的3天。

I've been at this for the past 3 days.

[TestClass]
class MyTestClass 
{

    DBEntities db;

    [TestInitialize]
    public void Initializer()
    {
       db = new DBEntities(); 
    }

    [TestMethod]
    public void test1()
    {
       db.Books.Add(new Book{ ...});
       db.SaveChanges();

    }

    [TestMethod]
    public void test2()
    {
       db.Books.Add(new Book{ ...});
       db.SaveChanges();
    }


    [TestCleanup]
    public void Clean()
    {
       db.Dispose(); 
    }

}

下面是DBEntities类的摘录:

Here's an excerpt of the DBEntities class :

public class DBEntities : DbContext
{
    public DbSet<Books> TheBooks{get;set;}
    ...
}

运行探查后,我发现这条消息:

After running a profiler, I noticed this message:

用户登录失败原因:无法打开明确指定的数据库。

"Login failed for user. Reason: failed to open the explicitly specified database."

很多 lockAcquired lockReleased 语句后面。

推荐答案

可能的问题是连接池?将SQL提供尝试preserve测试之间的连接,即使EF对象被设置?在这种情况下会是由同一用户有一个问题瓦特/多个连接到相同的DB

Might the issue be connection pooling? Would the SQL provider try to preserve the connection between tests, even though the EF object is disposed? In that case would it be having an issue w/ multiple connections to the same DB by the same user?

尝试显式关闭在清理连接:

Try explicitly closing the connection in your cleanup:

db.Database.Connection.Close();

这篇关于实体框架提供的异常:&QUOT;底层提供程序未能在开放和QUOT;。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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