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 Entity Framework and Databases Controlling Database Generation

Joel Brennan
Joel Brennan
18,300 Points

Cannot drop database "" because it is currently in use.

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in EntityFramework.dll

Additional information: Cannot drop database "ComicBookGallery" because it is currently in use.

2 Answers

Hi Joel!

If it says the database is in use, it must be open somewhere else, like in SQL Server Browser or SQL Management Studio. If not, remember to check Close existing connections in the delete database dialog, like so:

Database delete dialog

Let me know if it worked for you.

Joel Brennan
Joel Brennan
18,300 Points

Hi Thanks. I looked in SQL Management Studio, but I cannot see the connection listed to LocalDB.

** I was able to locate by: SqlLocalDB.exe i MSSQLLocalDB And connecting to the Instance pipe name.

All working now thanks.

Kevin Gates
Kevin Gates
15,052 Points

If you get that Close Existing Connections, first close all of your C# tabs first in Visual Studio, then run. That fixed it for me.