5061: ALTER DATABASE failed because a lock could not be placed on database
SQL ServerWhat 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.
More from this engine
- 40501The service is currently busy. Retry the request after 10 seconds
- 8645A time out occurred while waiting for memory resources to execute the query
- 8651Could not perform the operation because the requested memory grant was not available
- 3702Cannot drop database because it is currently in use
- 15138The database principal owns a schema in the database, and cannot be dropped
- 1934INSERT/UPDATE failed because the following SET options have incorrect settings
- 468Cannot resolve the collation conflict