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.
When a cumulative update (CU) or service pack finishes replacing files, SQL Server runs upgrade scripts against its system databases the first time it starts. If one script fails, the engine logs error 912 and error 3417 and does not start. Setup then shows "Wait on the Database Engine recovery handle failed. Check the SQL Server error log for potential causes."
Errors 912 and 3417 are the symptom, not the cause. The cause is the error logged immediately before 912. Read the errorlog, start the instance once with trace flag 902 to get it running, fix that cause, remove the flag, and restart so the upgrade script runs again.
What the error means
Microsoft documents that when SQL Server is upgraded or a CU is applied, "only the binaries are upgraded initially." The databases stay unmodified until the service restarts for the first time. The scripts are in the Install folder under the instance's MSSQL directory, for example C:\Program Files\Microsoft SQL Server\MSSQLXX.YYYY\MSSQL\Install.
The message text for error 912 begins "Script level upgrade for database '%.*ls' failed because upgrade step '%.*ls' encountered error %d, state %d, severity %d." It continues: "If the error happened during upgrade of the 'master' database, it will prevent the entire SQL Server instance from starting." Error 3417 follows: "Cannot recover the master database. SQL Server is unable to run."
The 912 message names the upgrade step and the error number it hit, such as sqlagent100_msdb_upgrade.sql with error 574. The 912 page is marked as applying to SQL Server 2019 (15.x) and later on Windows. The troubleshooting series describes the same failure for CUs, service packs and version upgrades.
Trace flag 902, in Microsoft's words, "Bypasses execution of database upgrade script when installing a Cumulative Update or Service Pack." It exists for troubleshooting. Microsoft's trace flag list states that it "isn't supported to run it continuously in a production environment."
Likely causes
Microsoft lists these error numbers under the "Wait on the Database Engine recovery handle failed" message: 574, 945, 1712, 2714, 4860, 5133, 6528, 15151, 15173, 17182, and failures where certificate-based principals own user objects. The 912 page also shows error 1101, insufficient disk space in tempdb, as an accompanying error.
| Cause | What you see | How to confirm |
|---|---|---|
| A user option such as IMPLICIT_TRANSACTIONS | Error 574, "CONFIG statement cannot be used inside a user transaction" | sp_configure 'user options' returns a non-zero value |
| Orphaned users | Error 574 with permission or login messages just before it | The orphaned-user query below returns rows |
| Jobs with an orphaned owner | Failure in msdb upgrade step |
The orphaned-job query below shows a NULL owner |
| SSISDB in an availability group | Error 945 | Microsoft documents error 945 for an SSISDB added to an availability group |
| Disk space exhausted | Error 1101 for tempdb before 912 | Free space on the tempdb volume |
| Another listed error | One of the numbers above in the errorlog | Match the number to Microsoft's page for it |
Prove the cause before changing anything
Read the errorlog first. In SSMS, Microsoft's route is Object Explorer, Management, SQL Server Logs, View, SQL Server Log. If the instance is down, open the ERRORLOG file directly: Microsoft says: "Locate and open the SQL Server Errorlog," then examine the log for "errors that occurred immediately before error 912." Once the instance is running under trace flag 902, EXECUTE sp_readerrorlog; shows the current log, and EXECUTE sp_readerrorlog 1; shows the previous one (ERRORLOG.1), which is the log from before the restart.
Read upward from the first 912 line and write down, in order:
- The first error that is not 912 or 3417.
- The upgrade step named in 912 (the
.sqlfile) and its error number. - Any message about a login, user, job or file that the script could not find.
Do not change anything yet. The sample pattern Microsoft shows for error 574 is a run of permission-granting lines in msdb that includes "A problem was encountered granting access to MSDB database for login '(null)'." A line like that points at a missing login, not at the 574 itself.
Fix
Everything below happens after the instance is running under trace flag 902. Microsoft documents three ways to start it. In SQL Server Configuration Manager, open the instance's Properties, Startup Parameters tab, type -T902, select Add, then start the service. From an administrative command prompt in the Binn folder, sqlservr.exe -s <instance> -T902 runs it in the console; press CTRL+C then Y to stop it. With net start, the default instance is NET START MSSQLSERVER /T902 and a named instance is NET START MSSQL$INSTANCENAME /T902.
Risk: with the flag on, the upgrade scripts are skipped, so the instance is running half-upgraded. Connect only to fix the cause, keep applications off it, and do not leave -T902 in place. Back out by removing -T902 from Startup Parameters (or stopping the console session) and restarting. Microsoft's guidance is: "Be sure to remove the trace flag once you have resolved the issue so the setup process can restart the upgrade script execution phase."
User options. Record the current value, then read what it contains against Microsoft's table of values. The table lists 2 as IMPLICIT_TRANSACTIONS and 8 as ANSI_WARNINGS. Microsoft's page for error 574 gives this script to clear all user options:
EXEC sp_configure 'user options', '0'
GO
RECONFIGURE WITH OVERRIDE;
GO
Disruptive step: this changes a server-wide default for every new login session. Applications that relied on those defaults behave differently. To back out, set user options back to the recorded number and run RECONFIGURE again. Microsoft's user options page says that "By default, no user options are configured", so a non-zero value has been configured by someone.
Orphaned users. Microsoft's query lists users with no matching server login:
SELECT dp.type_desc, dp.SID, dp.name AS user_name
FROM sys.database_principals AS dp
LEFT JOIN sys.server_principals AS sp
ON dp.SID = sp.SID
WHERE sp.SID IS NULL
AND authentication_type_desc = 'INSTANCE';
sys.database_principals is per database, so run the query in master and msdb at least, and in each user database that matters. Microsoft's page for error 574 points to "Troubleshoot orphaned users (SQL Server)" for resolution.
Risk: resolving an orphaned user re-maps it to a login or drops it, which changes who can reach the database. Record each user name and SID first. A re-mapping is backed out by re-mapping again. A dropped user's permissions cannot be restored except by granting them again, so do not drop a user until you know which application owns it.
Orphaned job owners. Microsoft's query:
SELECT sj.name AS Job_Name,
sl.name AS Job_Owner
FROM msdb.dbo.sysjobs_view sj
LEFT JOIN master.dbo.syslogins sl ON sj.owner_sid = sl.sid
WHERE sl.name IS NULL
OR sl.name <> 'sa'
ORDER BY sj.name
Microsoft's printed version of this query ends WHERE sl.name <> 'sa'. That filter removes the rows it is meant to find: where the owner login no longer exists, the join returns NULL for sl.name, and Microsoft's IS [NOT] NULL page says that "Comparison operators return UNKNOWN when either or both arguments are NULL." A row is returned only when the condition is true, so the orphaned rows never appear. The sl.name IS NULL OR term above keeps them. Microsoft's page for error 574 says: "Any record showing a NULL value here indicates that the owner of the applicable Agent Job is orphaned. Edit the job and change the owner to a valid login."
Risk: changing a job's owner changes whose permissions the job runs with. Record the old owner first so you can set it back.
Other errors. For 945, 1712, 2714, 4860, 5133, 6528, 15151, 15173, 17182 and certificate-owned objects, use Microsoft's page for that exact error number. Each is linked from the upgrade-failures page. For a tempdb space error, free or extend the volume before restarting.
After the fix, remove -T902 as described in the Risk: paragraph above, restart the service, and let the scripts run.
Example (illustrative): sql01 takes a CU and will not start. The errorlog shows error 574 before 912. The upgrade step named is sqlagent100_msdb_upgrade.sql. After starting with -T902, sp_configure 'user options' returns 10. Against Microsoft's table, 10 is 2 plus 8: IMPLICIT_TRANSACTIONS and ANSI_WARNINGS. The administrator records 10, sets the option to 0, removes -T902, and restarts. The scripts run and the errorlog shows the instance starting and the upgrade scripts completing.
Confirm the fix
Microsoft says that once SQL Server starts without trace flag 902, "the upgrade script will be executed again", and that you can confirm success in the SQL Server error log and the bootstrap folder. Check that no 912 or 3417 line appears after the restart. Then query SERVERPROPERTY('ProductVersion') and compare it with the CU you applied.
If the script fails again, Microsoft says to "check the SQL Server error log for other errors and troubleshoot the new errors." A second failure can mean a second cause rather than a failed fix.
What to watch afterwards
- Confirm
-T902is gone from Startup Parameters, and that no scheduled task or script starts the service with it. - Check Agent jobs and the applications that use the restored
user optionsdefault. - Before the next CU, run the orphaned-user and orphaned-job queries, and read
sp_configure 'user options'. - Before the next patch, take a full backup of the system databases, so that a failed master upgrade has a way back.
Read next
Related articles you may want next.
- HostingPatching SQL Server: cumulative updates, GDR and the order for availability groupsHow Microsoft ships SQL Server fixes, the difference between the cumulative update and GDR branches, how often each arrives, and the order Microsoft gives for patching availability group replicas with the least downtime.Read article
- 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
- HostingSQL Server support dates for hosted applications: what ended, what ends next, and upgrade checksWhich SQL Server versions still receive security updates, what Extended Security Updates require outside Azure, which versions can upgrade directly to SQL Server 2025, and what to check before an upgrade of a hosted business application.Read article
Risks and limits
These commands have not been run or lab-tested. The 574 and general upgrade-failure pages are dated 2023-08-17 and the 912 page covers SQL Server 2019 and later; confirm behaviour for your build. Microsoft's trace flag page advises contacting Microsoft SQL Customer Service and Support (CSS) if you hit an error during script upgrade mode. If the cause is not one of those listed, stop and ask Microsoft support rather than forcing the upgrade. The text of error 3417 itself names the last resorts for a master database that cannot be recovered: "Restore master from a full backup, repair it, or rebuild it." Each of those is a larger change than anything above, so plan it separately.
Sources
- MSSQLSERVER_912 — Microsoft Learn, page dated 2026-03-05, accessed 18 November 2026
- Troubleshoot upgrade script failures when applying an update — Microsoft Learn, page dated 2023-08-17, accessed 18 November 2026
- SQL Server upgrade fails with error code 574 when executing update database scripts — Microsoft Learn, page dated 2023-08-17, accessed 18 November 2026
- Trace flags (DBCC TRACEON) — Microsoft Learn, page dated 2026-09-28, accessed 18 November 2026
- Server configuration: user options — Microsoft Learn, page dated 2026-01-21, accessed 18 November 2026
- View the SQL Server error log in SQL Server Management Studio (SSMS) — Microsoft Learn, page dated 2026-06-23, accessed 18 November 2026
- sys.sp_readerrorlog — Microsoft Learn, page dated 2026-10-14, accessed 18 November 2026
- SERVERPROPERTY — Microsoft Learn, page dated 2026-09-21, accessed 18 November 2026
- IS NULL and IS NOT NULL (Transact-SQL) — Microsoft Learn, page dated 2026-09-22, accessed 18 November 2026
- dbo.sysjobs (Transact-SQL) — Microsoft Learn, page dated 2026-08-14, accessed 18 November 2026
- sys.syslogins (Transact-SQL) — Microsoft Learn, page dated 2023-03-01, accessed 18 November 2026
This article was originally published on .