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
It will list all running processes.
Find your database name under dbname column.
Copy the SPID for that record and run this command
Try accessing the database now.
You should be able to access it successfully.