Cannot drop database "%.*ls" because it is currently in use.

Error Message:
Msg 3702, Level 16, State 3, Line 2
Cannot drop database “%.*ls” because it is currently in use.

Severity level:
16.

Description:
This error message appears when you try to DROP a database for which open connections exist.

Consequences:
The T-SQL statement can be parsed, but causes the error at runtime.

Resolution:
Error of the Severity Level 16 are generated by the user and can be fixed by the SQL Server user. You cannot drop a database while you are connected to it. You must switch the database context before you can drop a database.

Versions:
All versions of SQL Server.

Example(s):
USE master
CREATE DATABASE showme
GO
USE showme
DROP DATABASE showme

Remarks:
In the above example the error is raised because the database context points to the database that is about to be dropped. This is a quite common mistake. To execute the batch successfully, you need to switch the database context before you can drop the database.

]]>

Leave a comment

Your email address will not be published.