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 (http://blog.SQLAuthority.com)

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

  1. 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.

    Like

  2. 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.

    Like

  3. 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

    Like

  4. 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.

    Like

  5. 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.

    Like

  6. 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.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s