C# Entity Framework Basics Extending Our Entity Data Model Using a One-to-Many Relationship

Data base still in use error

After closing all programs and tabs that used the Database I still get the error saying that the Database can not be dropped because it is in use. When I watch the status of the server in sqllocaldb.exe I noticed that the connection is closing but only after some amount of time (5 - 10 min).

Is this normal or did I forget anything. I know I could just close it manually but why even is there a dispose method in the when it is not working properly.

1 Answer

Allan Clark
Allan Clark
10,800 Points

the Dispose method should rarely be called directly. It is better practice to create the object with a 'using' statement. This will make sure the connection is closed even if the code is stopped or errored out before the Dispose method would be called.

Would need to see code to provide a more precise answer.

I am already using a using statement, maybe it's because my VM is a little bit slow. When I call the contexts Dispose method, the method executes but the Database is closing with some delay.

Thanks anyway ;