Msg 1807 Could not obtain exclusive lock on database 'model'. Retry the operation later.

2014-08-12

Errors like this:

Msg 1807, Level 16, State 3, Line 1
Could not obtain exclusive lock on database 'model'. Retry the operation later.
Msg 1802, Level 16, State 4, Line 1
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.


Solution (reference from http://dbasqlserver13.blogspot.com/2013/10/error-1807-could-not-obtain-exclusive.html):

Some sessions locked the "Model" database"
Use DMV <sys.dm_tran_locks> to identify the locked session

--00 find out if the Model is locked
Use master 
GO
IF EXISTS(SELECT request_session_id  FROM sys.dm_tran_locks
WHERE resource_database_id = DB_ID('Model'))
PRINT 'Model Database being used by some other session'
ELSE
PRINT 'Model Database not used by other session'


--01 if locked, who locked it

DECLARE @reqID INT
SELECT @reqID = request_session_id  FROM sys.dm_tran_locks
WHERE resource_database_id = DB_ID('Model')
--02 what is the session doing on it?
DBCC InputBuffer(@reqID)


Newer Older