DBAtlas · Database operations atlas

5061: ALTER DATABASE failed because a lock could not be placed on database

SQL Server

What does it mean?

An ALTER DATABASE operation (e.g., switching to single-user mode, changing a file, setting an option) could not acquire the required lock on the database because other active connections/sessions are using it.

Why does it happen?

The operation was attempted while the database was in use; the exclusive lock required for SET SINGLE_USER, RESTRICTED_USER or similar option changes could not be acquired because of active user connections. Common during frequent deploys/maintenance while application connections are open.

How to fix it

Identify the other sessions connected to the database (sys.dm_exec_sessions, sp_who2) and close them safely. For maintenance, change the mode while rolling back open transactions with the ROLLBACK option: ALTER DATABASE [db] SET SINGLE_USER WITH ROLLBACK IMMEDIATE; Perform the operation when application traffic is low or in a maintenance window. Remember to switch back to MULTI_USER when done.

Open in DBAtlas →

More from this engine