Make ADO.NET (and EntityFramework) database release

I'm creating and dropping databases on the fly for some integration tests. I am doing all my database management at the ADO.NET layer. For tests, I use Entity Framework because entities are one part of what I am testing. The problem is that after this:

using (ProjectEntities db = new ProjectEntities(cs)) {
}

      

I can no longer drop the database. He says he is being used. How to release it so that it can be dropped?

I had the same problem at the ADO.NET layer and did this:

new SqlCommand("USE [master]", DatabaseConnection).ExecuteNonQuery();

      

but I'm not sure how to accomplish something with the same effect for an Entity Framework connection. I am trying to manually delete the db object (although the use clause should guarantee this) and I also tried to manually close the db.Connection. Nothing helped. If I could work directly with SQL without connecting to the Entity Framework, I believe I can do it. Or maybe there is another way?

+2


source to share


1 answer


You might need to explicitly close all connections, I believe the connection is being merged and this is one of the pooled connections that still maintains an active DB connection. Try to useSqlConnection.ClearAllPools



I have written about a similar issue in Entity Framework Object Context - AWAITING COMMAND .

+5


source







All Articles