You are here:Home » SQL Server Problems » Could not obtain exclusive lock on database 'model' - SQL Server

Could not obtain exclusive lock on database 'model' - SQL Server

Problem:
One day when I was creating a new database, I was notified as "Could not obtain exclusive lock on database 'model'. Retry the operation later" and I could not able to successfully to create that database.

The error,

TITLE: Microsoft SQL Server Management Studio
------------------------------
Create failed for Database 'NewDatabase'. (Microsoft.SqlServer.Smo)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.0.1600.22+((SQL_PreRelease).080709-1414+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Create+Database&LinkId=20476
------------------------------
ADDITIONAL INFORMATION:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
------------------------------
 Could not obtain exclusive lock on database 'model'. Retry the operation later.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors. (Microsoft SQL Server, Error: 1807)

For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.00.1600&EvtSrc=MSSQLServer&EvtID=1807&LinkId=20476
------------------------------


I have the checked any open transactions which have locked the "Model" database, But no any processes were locked in this database. Everything was OK with this database. Finally, I have checked the processes or connections to this database in process, And one connection was from Management studio.

The script to find connections of the "Model" database.
USE MASTER
GO

SELECT 
* 
FROM SYS.SYSPROCESSES
WHERE dbid  = DB_ID('model')

GO
Solution:
After disconnecting from "Model" database I have tried one more time to create a new database. Then I was able to successfully create it. This is because of a new database is created from "Model" database.

I would like you to share your experience for such error and what you did for the resolution for the same. Also share the reason for this type of errors.