While working on query optimization project, I encountered following error.
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.
The resolution of above problem is quick and easy.
Fix/Workaround/Solution:
Disconnect and Reconnect your SQL Server Management Studio’s session. Your error will go away.
Reference: Pinal Dave (https://blog.sqlauthority.com)
24 Comments. Leave new
Just a few questions please:
1) What causes this issue?
1.a) Is the problem with the client or the server?
1.b) Does this only exist in “Create Database” commands?
2) What Version of SQL Server does this affect?
2.a) Specifically, what build we you using when you got the error
2.b) Does this exist in SQL 2005 and Up?
2.c) Is it isolated to 32 or 64 bit?
3) Is there a CU or SP Fix to this yet?
Thank you.
thanks !!
did not fix the problem with sql server 2008 express
Thanks…works like charm!!!!
did not fix the problem with sql server 2000 here either!
does not fix the problem in SQL 2008 on a subscription of create database. MODEL is set to SHARE also.
works for 2008 R2
The issue is an active connection to the db Model. So you need to either kill any such processes or change the current db in any current sessions before trying your operation.
thank’u sir………………………
Wonderful..saves a lot.to get rid of pain in the necek..
it worked….thank a ton
Works fine after removing connection of Model DB from VS 2008
Hi,
I have the same error when creating a new database in my SQL Server 2008 R2 instance. I have looked through a couple of tech forums and tried the following suggested methods. So far nothing works for me, Short of restarting the SQL server machine which I have yet to try as it is a production machine. Any additional feedback would be appreciated.
A) Disconnect and Reconnect your SQL Server Management Studio’s session.
B) — find the locks on the model db and kill them
SELECT ‘KILL ‘ + CONVERT(varchar(10), l.request_session_id)
FROM sys.databases d, sys.dm_tran_locks l
WHERE d.database_id = l.resource_database_id
AND d.name = ‘model’
C) Reboot the SQL Server machine
It Worked.
I would suggest to close all open connections to the target server, even if a user login properties window is open with altering tick mark for the Model database sql will not allow you to create new db.
I am still getting the same error ( SQL server 2008 R2)
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.
Please suggest.
Just run sp_who2 and see who / what is connected to the model database. In my case it was a user session from their PC. Got them to logoff instance and replication was configured fine.
Thank you! Could have saved couple of hours if I had googled earlier!
The issue is that the database is locked by another session. Try running this to findout the session:
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’
Thanks ravicioso.
Thanks Dave. I encountered this fun little error I when attempting to build configure SharePoint 2013 via Powershell for a client
New-SPWebApplication : Could not obtain exclusive lock on database ‘model’. Retry the operation later
Your ‘fix’ almost worked
The issue in my scenario is create by me using SQL Management Studio on the same machine I am running my PowerShell build scripts from.
I always prefer to run SQL ServerManagement Studio from my desktop and PowerShell on the server I am installing on. But sometime when you connect to client systems you are limited by what they dictate. I was able to resolve this by shutting down SSMS and reboot the server and then continue with the PowerShell install.
Brian Loring (@itgeekbrian) – Thanks for the comment.