Search

Showing posts with label ALTER DATABASE failed because a lock could not be placed on database. Show all posts
Showing posts with label ALTER DATABASE failed because a lock could not be placed on database. Show all posts

Tuesday, October 18, 2011

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


Sometime when we run the CheckDB query (dbcc CheckDB('DemoDB', REPAIR_ALLOW_DATA_LOSS) or while taking the database offline, we may face the following error:


ALTER DATABASE failed because a lock could not be placed on database 'DemoDB_DB'. Try again later.


Below is the simple solution to this error message:
Run sql command
EXEC sp_who2 


It will list all running processes.
Find your database name under dbname column.
Copy the SPID for that record and run this command


KILL <SPID> 


Try accessing the database now.
You should be able to access it successfully.