我有一个考试发生什么是,当首先执行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;} ... }
运行分析器后,我注意到这个消息:
“Login Failed for user. Reason: Failed to open the explicitly specified database.”
经过很多lockAcquired和lockReleased语句.