SQL SERVER – FIX: Error: 1807 Could not obtain exclusive lock on database ‘model’. Retry the operation later.

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)

SQL Error Messages, SQL Scripts
Previous Post
SQLAuthority News – 1200th Post – An Important Milestone
Next Post
SQL SERVER – Find Location of Data File Using T-SQL

Related Posts

24 Comments. Leave new

  • Lorenzo Raras
    January 3, 2010 7:10 pm

    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.

    Reply
  • thanks !!

    Reply
  • did not fix the problem with sql server 2008 express

    Reply
  • Thanks…works like charm!!!!

    Reply
  • did not fix the problem with sql server 2000 here either!

    Reply
  • Richard Granucci
    November 3, 2011 3:22 am

    does not fix the problem in SQL 2008 on a subscription of create database. MODEL is set to SHARE also.

    Reply
  • works for 2008 R2

    Reply
  • 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.

    Reply
  • thank’u sir………………………

    Reply
  • Wonderful..saves a lot.to get rid of pain in the necek..

    Reply
  • Mahesh Kharawatkar
    April 11, 2013 2:54 pm

    it worked….thank a ton

    Reply
  • Harish Thakur
    April 15, 2013 10:48 pm

    Works fine after removing connection of Model DB from VS 2008

    Reply
  • 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

    Reply
  • Shriraj Kulkarni
    July 25, 2013 10:16 am

    It Worked.

    Reply
  • 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.

    Reply
  • 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.

    Reply
  • braveheart1326
    February 12, 2014 5:15 pm

    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.

    Reply
  • Thank you! Could have saved couple of hours if I had googled earlier!

    Reply
  • 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’

    Reply
  • Brian Loring (@itgeekbrian)
    July 15, 2015 11:01 pm

    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.

    Reply

Leave a ReplyCancel reply

Exit mobile version