About this article: This article is reviewed against the cited sources. This is source research, not lab validation. Check the stated versions and your own requirements before making changes.
You run a routine task, such as creating a database, and SQL Server answers with error 1807: "Could not obtain exclusive lock on database 'model'. Retry the operation later." The task did not run. SQL Server needed to be the only user of the model database for a moment, and it was not.
Microsoft's page for the error is short and names no cause beyond a connection using the database. What can be added is what the model database is for, so the message makes sense, and how to find who is connected to it.
What the error means
Microsoft lists error 1807 as event ID 1807, symbolic name CANNOT_EX_LOCK, with the message text "Could not obtain exclusive lock on database '%.*ls'. Retry the operation later." The placeholder is replaced with the database name, so the same error can name other databases. What follows is about the case where the name is model.
The explanation: "An operation that required exclusive access to the database was unable to obtain it." The user action: "Disconnect all the connections to that database or try the query again later."
The model database matters because of what Microsoft says it does. The model database "is used as the template for all databases created on an instance of SQL Server". When a CREATE DATABASE statement is issued, "the first part of the database is created by copying in the contents of the model database", and some of the settings of model are also used when tempdb is created at start-up. Microsoft's pages do not say which operation takes the exclusive lock on model, and they do not say that CREATE DATABASE does. A reasonable guess is that anything that copies or alters the template wants nobody else in it; treat that as a guess to test, not as Microsoft's statement.
What model holds is also worth knowing before anyone reaches for a drastic fix. Microsoft's pages say that new databases inherit option settings from model (the CREATE DATABASE page's example is auto shrink being set to true in model and then in any new database), and that "Changing operations in the model database doesn't affect existing databases." Microsoft's model page also lists operations that cannot be performed on model, including setting the database to OFFLINE and dropping it, so the usual maintenance tricks for freeing a database are not available here.
Likely causes
Microsoft's page gives the explanation above and the action "Disconnect all the connections to that database", which points at connections that are using the database. The rows below are the ways that can happen.
| Situation | How it shows |
|---|---|
A session has model as its current database |
A query of the sessions shows model for that connection |
A tool left a window open in model |
An SSMS query window, or a monitoring or backup tool, connected to model |
| A second administrative task is running at the same moment | Two people or two jobs changing system databases together |
A connection can be in model without anyone meaning it to be. A login's default database may be model, or a script may have run USE model and stayed there.
Prove the cause before changing anything
All of this only reads.
- Note the exact message and the statement that was running when it appeared. Note the database name in the message.
- Find the sessions whose current database is
model. Microsoft'ssys.dm_exec_sessionsview has adatabase_idcolumn ("ID of the current database for each session"), andsys.databaseshas the database names:
SELECT s.session_id, s.login_name, s.host_name, s.program_name, s.status
FROM sys.dm_exec_sessions AS s
JOIN sys.databases AS d ON d.database_id = s.database_id
WHERE d.name = N'model';
Microsoft describes is_user_process as 0 for a system session. Add AND s.is_user_process = 1 to see only user sessions.
- Look for your own session in the result. Your own SSMS window may be one of the connections, and a window that finished its work can still be sitting in
model. - For each session listed, find who owns it from the host name and program name. If the row is a monitoring product, an agent job or a backup tool, ask its owner before anything is disconnected.
- Look for a login whose default database is
model. The query Microsoft gives on its error 4064 page lists a login's default database:
SELECT name, default_database_name
FROM sys.server_principals
WHERE type = 'S' AND name = '<sql-login>';
Example (illustrative): at contoso.com.au an engineer tries to create a database for a new application and gets error 1807 naming model. The session query shows two rows: session 57, SSMS on ADMIN-PC02 with login CONTOSO\jlee, and session 63 for an inventory tool on APP04, both with model as the current database. Session 57 is the engineer's colleague's open query window. Session 63 is a tool whose login has model as its default database.
Fix
Microsoft gives two actions: disconnect everything that is using the database, or try again later.
Try the operation again later
This changes nothing. If the sessions in the list are brief, as an agent job step or a short query, wait a few minutes and run the failed statement again. If the same sessions are still there, you are dealing with a long-lived connection.
Decide between waiting and disconnecting
Microsoft gives two actions: disconnect all the connections to the database, or try the query again later. Its page gives no rule for choosing between them. In our reading, a session that is still listed after a few minutes is unlikely to leave by itself, so its owner would have to disconnect it. Whichever you choose, repeat the session query before you run the failed statement again, so that you know what you are changing.
Disconnect the sessions that are using model
Microsoft's action is to disconnect all the connections to that database. For an SSMS window this means closing the query window, and for an application it means asking its owner to disconnect.
Save first. Write down for each session the session ID, the login, the host name, the program name and the status from the session query, so the owner knows what was disconnected.
Risk: Disconnecting a session ends that person's or program's connection. A query in progress stops, and work in an open transaction is not saved. Tools that reconnect on their own will come back and may land in model again if their login's default database is model.
Ask each owner to close or disconnect the connection that has model as its database. Check the session query again until no row remains, then run the original operation.
To undo it: there is nothing to restore on the server. Ask each owner to reconnect, and if they should not return to model, ask for the login's default database to be changed first. Microsoft's ALTER LOGIN ... WITH DEFAULT_DATABASE statement is documented on its error 4064 page.
No KILL statement is printed here. Ending a session with KILL rolls back its work and cannot be undone, and Microsoft says to use it carefully. If the owner of a session cannot be reached and the session must be ended, treat it as a decision for the person responsible for the server.
Confirm the fix
- The session query returns no rows for
model. - The original operation completes with no error 1807.
- Open the SQL Server error log and confirm there is no new 1807 entry for the time of the retry.
What to watch afterwards
- Repeat occurrences. If error 1807 returns on the same schedule, compare the time with scheduled jobs, backup tools and monitoring agents that connect to the instance; the session query run at that time shows which of them is in
model. - Logins whose default database is
model. Moving them removes the main reason connections land there. - Admin tools and scheduled jobs that are set to connect to
model. - Changes to
modelitself. Microsoft recommends backing it up if you put template information in it.
Read next
Related articles you may want next.
- Backup & RecoverySQL User Databases Survived but the Instance Is Gone: Plan System-Database RecoveryBuild a version-aware recovery inventory for master, msdb, model and separately held instance dependencies.Read article
- Backup & RecoverySQL Server restore error 3101: exclusive access could not be obtained because the database is in useRESTORE fails with error 3101 because sessions still use the database. Find them, clear them safely, restore, and avoid the data-loss traps.Read article
- TroubleshootingSQL Server error 924: database is already open and can only have one user at a timeSQL Server error 924 means a database is in single-user mode and its one connection is taken. Find the session, then return it to MULTI_USER.Read article
Risks and limits
These queries have not been run in a lab. Microsoft's error 1807 page has a short explanation and two actions. It does not say which operations ask for the exclusive lock, how long to wait before retrying, or how to disconnect sessions. The idea that creating a database is a trigger is a guess from how Microsoft describes the model database, not something its page says.
Sources
- MSSQLSERVER_1807 — Microsoft Learn, page dated 2023-02-28, accessed 1 December 2026
- model Database — Microsoft Learn, page dated 2026-01-21, accessed 1 December 2026
- sys.dm_exec_sessions (Transact-SQL) — Microsoft Learn, page dated 2026-11-02, accessed 1 December 2026
- MSSQLSERVER_4064 — Microsoft Learn, page dated 2026-03-18, accessed 1 December 2026
- CREATE DATABASE (Transact-SQL) — Microsoft Learn, page dated 2026-09-21, accessed 1 December 2026
- KILL (Transact-SQL) — Microsoft Learn, page dated 2026-09-21, accessed 1 December 2026
This article was originally published on .