Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,548 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 ;