可能重复:
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;}
...
}