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#

Cannot drop database issue

I'm getting an exception being thrown "System.Data.SqlClient.SqlException: 'Cannot drop database "ComicBookGallery" because it is currently in use.'".

I am running the code in a using statement as in the video so I know that the Dispose method should be closing connections.

Interestingly - I can run the code multiple times without issue however as soon as I've clicked on view data on one of the tables, even if I then close the tab I get the exception again. Is this to do with Visual Studio rather than my code? Is there a way in visual studio to close all existing connections without deleting the database? It doesn't matter much here but in the future I may want to inspect the table data without then having to delete the database.

Simply closing and reopening Visual studio then means I can run the code again however this is a work around not a fix. I'd appreciate if anyone had any insight into this