SQL Server error 3702: Cannot drop database, currently in use
DROP DATABASE failed because sessions, possibly including your own, are connected to it. Close them or set the database to SINGLE_USER first.
- Error number
3702- Severity
- 16
- Category
- Names and objects
What it means
SQL Server won't drop a database while anyone is using it. Your own connection counts if its current database is the one you are dropping.
Common causes
- Your session ran
USEon the database, or connected to it directly. - Applications, jobs, replication or other users have open connections.
How to fix it
-
Move your own session away, close other connections, then drop.
USE master; ALTER DATABASE OldDb SET SINGLE_USER WITH ROLLBACK IMMEDIATE; DROP DATABASE OldDb;
-
Check who is connected before forcing them out.
SELECT session_id, login_name, program_name FROM sys.dm_exec_sessions WHERE database_id = DB_ID(N'OldDb');
Related errors
3101Exclusive access could not be obtained5030Database couldn't be exclusively locked55006PostgreSQL: object in use
More names and objects errors
208Invalid object name207Invalid column name4104Multi-part identifier not bound209Ambiguous column name2812Could not find stored procedure2714There is already an object named3701Cannot drop, object not found8144Too many arguments specified
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.