// SQL Server error reference

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
Error message
Cannot drop database "%.*ls" because it is currently in use.

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 USE on the database, or connected to it directly.
  • Applications, jobs, replication or other users have open connections.

How to fix it

  1. Move your own session away, close other connections, then drop.

    USE master;
    ALTER DATABASE OldDb SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
    DROP DATABASE OldDb;
  2. 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

More names and objects errors

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.

// fewer errors, faster fixes

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.