Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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.

Damien Bactawar
Damien Bactawar
8,549 Points

I am experiencing the same problem. Did you find a solution for it?

1 Answer

Allan Clark
Allan Clark
10,810 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 ;