SQL Server error 5030: Database couldn't be exclusively locked
An ALTER DATABASE operation such as a rename or collation change needs exclusive access, but other sessions are using the database.
- Error number
5030- Severity
- 16
- Category
- Names and objects
What it means
Some database-level changes, such as ALTER DATABASE ... MODIFY NAME or changing the database collation, require that no other session is using the database. If one is, SQL Server raises 5030.
Common causes
- Other connections to the database, including your own query window or Object Explorer.
- Background tasks or applications that keep connections open.
How to fix it
-
Take the database into single-user mode for the change.
USE master; ALTER DATABASE SalesDb SET SINGLE_USER WITH ROLLBACK IMMEDIATE; ALTER DATABASE SalesDb MODIFY NAME = SalesDb2025; ALTER DATABASE SalesDb2025 SET MULTI_USER;
-
Schedule the change in a maintenance window, since
ROLLBACK IMMEDIATErolls back other users' open transactions.
Related errors
3101Exclusive access could not be obtained3702Cannot drop database, currently in use1222Lock request time out period exceeded
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.