Showing posts with label Cannot drop database Error Msg 3702. Show all posts
Showing posts with label Cannot drop database Error Msg 3702. Show all posts

Wednesday, January 11, 2017

Cannot drop database Error Msg 3702

I tried to remove my recently created database, I got following error.

Msg 3702, Level 16, State 3, Line 2
Cannot drop database “DataBaseName” because it is currently in use.

The common mistake was the connection open with this database and trying to drop it.
The following commands will raise above error:
USE DataBaseName;
GO
DROP DATABASE 
DataBaseName;
GO
Solution:
The following commands will not raise an error and successfully drop the database:

USE Master;
GO
DROP DATABASE DataBaseName;
GO

If you want to drop the database use master database first and then drop the database.

NOTE : Sometimes this code does not work and we are still getting the same issue. In that case we have to close the SQL Server and then retry. I am sure it works.
Basically when you restart the server that will drop all the open connection and so you'll be able to drop it.  :)