Search

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.

2 comments:

  1. Hello Sir,

    I tried with your suggestion but still it is showing same error for me

    Msg 5061, Level 16, State 1, Line 2
    ALTER DATABASE failed because a lock could not be placed on database 'MYDB'. Try again later.
    Msg 5069, Level 16, State 1, Line 2
    ALTER DATABASE statement failed.


    I was trying to take it offline for few minutes but now i am not able to even use it..

    Please tell me any resolution of this problem. Thank you

    ReplyDelete
    Replies
    1. Check below link to solve the error:

      http://stackoverflow.com/questions/4673065/alter-database-failed-because-a-lock-could-not-be-placed-on-database

      Delete