Skip to content

Est. 2011ยทMicrosoft Partner ID 7033487ยทDelivery under 3 minยทSupport 7 days a week

Your vault is empty.

License Error 18401

Error 18401 and 17187: SQL Server Is Not Ready to Accept Connections

10 min read Updated October 5, 2026 SQL Server

Fix it now

The engine is running but not open for business. Error 18401 is published as a login refused because the server is in script upgrade mode and only an administrator can connect; error 17187 is published as SQL Server not being ready to accept new client connections. Neither is a login, corruption or licensing failure, and restarting makes both worse.

Run as a sysadmin, which script upgrade mode still admits

SELECT session_id, command, percent_complete
FROM sys.dm_exec_requests
WHERE session_id < 50;

SELECT name, state_desc FROM sys.databases;
  1. Do not restart the service. Each restart makes the upgrade scripts, or the rollback recovery is working through, begin again.
  2. Read the current error log. During script upgrade it names each script as it runs; during recovery it prints a percentage per database.
  3. If a database reports 922 it is being recovered, so wait. If it reports 927 a restore against it was never completed.
  4. Finish an interrupted restore with RESTORE DATABASE [YourDb] WITH RECOVERY;, but only once there are no further backups to apply.
  5. If the log shows an upgrade script failing, fix what it names and restart so the scripts run again from where they can succeed.

Tell the application owners the wait is finite. Both codes are transient, and a client that retries with a short backoff will connect on its own once the engine opens.

If ordinary logins are being accepted again you are done. If the scripts are failing rather than running, the next section covers what to change.

Why it happens

Two different waits produce one symptom, and telling them apart decides whether you do anything at all.

Script upgrade mode happens after patching. The installer replaces the binaries, but the contents of the system databases and the metadata inside every user database still have to be brought up to the new build, and that work is done by scripts the engine runs on its first start afterwards. Until they finish, only administrators are admitted and everyone else is refused with 18401, whose published text names script upgrade mode explicitly.

Crash recovery is the other wait. After an unclean shutdown every database replays its log, and one that was in the middle of a large transaction has to roll it back before it can open. That database answers 922, published as being recovered and waiting until recovery is finished. The rest of the instance is usable throughout, which is why some applications work and others do not.

Error 17187 sits across both. Its published text is that SQL Server is not ready to accept new client connections and to wait a few minutes before trying again. On a busy server a restart creates a connection storm, so the first minute after a service start produces a burst of these while nothing is wrong at all. Error 927 is the odd one out: it is published as a database that cannot be opened because it is in the middle of a restore, which is a state somebody left behind rather than a wait.

A cumulative update is still applying its scripts

You have this one if The instance was patched, restarted once, and the log shows scripts running in sequence.

  1. Leave it alone and watch the log. Part of the work is per database, so an instance with many databases takes proportionally longer.
  2. Let the application reconnect loops run; they will succeed without intervention.
  3. Once the log reports the upgrade complete, confirm every database is online before releasing the instance.

An upgrade script failed against a database

You have this one if The log shows an error inside a script, and the instance either stops or stays in upgrade mode across restarts.

  1. Read the failing line. The usual blockers are a database that is read-only, offline, in single-user mode or in emergency mode.
  2. Put those databases back to a normal state, for example ALTER DATABASE [YourDb] SET READ_WRITE; or SET ONLINE;
  3. Restart the service so the scripts run again from where they can succeed.

If the same failure prevents master from recovering you will see error 3417 instead, and Microsoft documents a failed cumulative update as one of its causes. That is a different and more serious article.

Recovery is rolling back a large transaction

You have this one if 922 on one database after an unclean shutdown, with a rollback percentage in the log that is climbing slowly.

  1. Watch progress in the error log and in sys.dm_exec_requests, where the startup task reports percent complete.
  2. Do not restart. Undo work already done is repeated after every restart, so restarting extends the outage.
  3. Once it is online, look at what was running when the instance stopped and consider breaking that work into smaller transactions.

A restore was interrupted and never completed

You have this one if 927 on a database that shows as RESTORING, usually after a cancelled refresh from production.

  1. List what has been applied from msdb.dbo.backupset for that database, ordered by backup finish time.
  2. If the sequence is complete, bring it online with RESTORE DATABASE [YourDb] WITH RECOVERY;
  3. If backups are still outstanding, restore them WITH NORECOVERY and only then finish with recovery.

Clients arrived during the first seconds of startup

You have this one if A short burst of 17187 immediately after a planned restart, then nothing.

  1. Confirm the burst stops on its own by checking the log a minute later.
  2. Give the application a connection retry with a short backoff rather than treating the error as a failure.
  3. If the burst is long rather than brief, look for a database still recovering behind it.

Full reference

Which wait you are in

What you see What is happening
18401 for ordinary logins while sysadmins get in Upgrade scripts are running after a patch
17187 for everyone, briefly, after a restart Startup has not finished and connections arrived early
922 on one database only That database is being recovered
927 on one database only A restore against it was started and never completed
The log stops mid-script and the service exits An upgrade script failed; the reason is the line above

Trace flag 902, and what it costs you

Trace flag 902 is documented as bypassing execution of the database upgrade script when installing a cumulative update or service pack. It is global scope only. It exists so you can get into an instance whose scripts cannot run, fix whatever is blocking them, and let them run properly afterwards.

Microsoft states that this trace flag is meant for troubleshooting failed updates during script upgrade mode and that it is not supported to run it continuously in a production environment, because the upgrade scripts have to execute successfully for the update to be complete. Microsoft also recommends contacting support if you hit an error during script upgrade mode. Treat 902 as a way in, remove it, and let the scripts finish before the instance carries production work.

Watching progress without guessing

Where to look What it tells you
The current ERRORLOG Each upgrade script by name as it runs, and a recovery percentage per database
sys.dm_exec_requests for low session ids The startup task, its command and percent_complete
sys.databases.state_desc Which databases are ONLINE, RECOVERING, RESTORING or SUSPECT
SELECT @@VERSION; Whether the build you installed is actually the one now running

Making the next one shorter

  • Take a full backup before patching, so a failed upgrade has a route back that does not depend on repair.
  • Keep transactions short. Recovery time after a crash is dominated by how much log has to be redone and undone, not by anything you can configure at the last minute.
  • Where your version supports it, Accelerated Database Recovery makes rollback of long transactions far less painful, and indirect checkpoints shorten redo after a crash.
  • Patch a replica rather than the only copy, if you have one. The wait is the same length; the outage is not.

What not to do

  • Do not restart to speed things up. Both waits restart from the beginning.
  • Do not set a slow database offline to make an alert stop and then forget it. Bring it back with a proper restore or recovery.
  • Do not treat 18401 as a permissions problem and start granting rights. The refusal is by design and applies to every non-administrator login while the scripts run.
  • Do not leave trace flag 902 in the startup parameters after the incident.

When a licence is the actual fix

Nothing above costs money, and waiting is the right answer to most of it. What you cannot fix by waiting is the outage itself: patching means an interruption while the scripts run, and crash recovery means one you did not schedule. The usual way out is a second replica you fail over to, patching one side at a time. On SQL Server 2025 that means an availability group, which the edition table lists as an Enterprise feature with support for up to eight secondary replicas; Standard offers only a basic availability group, documented as two replicas with a single database and a secondary that is neither readable nor able to take backups. If that is the direction you are heading, Arco can supply SQL Server 2025 Enterprise (2-core pack) licences and work through the core count your topology actually needs first.

Every code this article covers

Code What it points at Source
18401 Login failed because the server is in script upgrade mode and only an administrator can connect at this time Microsoft Learn
17187 SQL Server is not ready to accept new client connections; wait a few minutes before trying again Microsoft Learn
922 The database is being recovered, and the request is waiting until recovery is finished Microsoft Learn
927 The database cannot be opened because it is in the middle of a restore Microsoft Learn

Confirm the fix worked

  1. SELECT name, state_desc FROM sys.databases; reports everything ONLINE.
  2. An ordinary application login connects, not just a sysadmin.
  3. The error log ends the upgrade or recovery sequence with a completion line and nothing after it.
  4. SELECT @@VERSION; matches the build you installed, so you know the patch is fully applied.
  5. Trace flag 902 is not in the startup parameters.

Questions people ask about this

How long does script upgrade take?

It depends on how many databases the instance holds, because part of the work is per database, and on how fast the storage is. The error log gives a running commentary. What it never does is finish faster because you restarted.

Would a higher edition make recovery quicker?

Not directly. Recovery speed is governed by how much log has to be replayed and how fast the storage is. What a higher edition buys is a second replica, so you fail over instead of waiting.

Can I let applications retry through the wait?

Yes, and it is the right pattern. Both 18401 and 17187 are transient, and 17187’s own text tells the caller to wait a few minutes and try again. A retry with a short backoff succeeds without anyone intervening.

The scripts failed and now the service will not start at all. What am I looking at?

Check the log for error 3417. Microsoft documents a failed cumulative update or service pack upgrade script as one of the causes of master failing to recover, which stops the instance rather than restricting it. That is a recovery problem, not a waiting problem.

Is 922 the same as the database being upgraded?

No. The published text for 922 is that the database is being recovered and the request is waiting until recovery finishes. Script upgrade is an instance-wide state that shows up as 18401 for ordinary logins.

Related error codes

Was this article helpful?

Your feedback helps us improve our documentation.

Related articles

Free Fix Error 53 and Error 26: SQL Server Instance Not Found on the Network Free Fix Error 15023 and Orphaned Users: Fixing SID Mismatches After a Restore Free Fix Error 1101 and 665: Out of Disk Space and NTFS File System Limits Free Fix Error 8152: String or Binary Data Would Be Truncated – Find the Column
โ† Back to Knowledge Base