实体框架无法登录数据库

时间:2011-02-15 16:13:21

标签: c# .net entity-framework entity-framework-4

  

可能重复:
  Entity Framework giving exception : “The underlying provider failed on Open.”

我有一个测试。发生的事情是,每当test1首先执行时,test2就会失败并显示消息:

"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都会以相同的消息失败。

过去3天我一直在这。

[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类的摘录:

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

0 个答案:

没有答案