How to fix Error 917 on Windows Server 2025 / Windows 11

Troubleshooting Guide: Error 917 – Upgrade Script Batch Compilation Failure

Why This Error Happens

Error 917 occurs when SQL Server attempts to run an internal upgrade script against a system or user database, but encounters a T-SQL compilation error within that script batch. This is typically caused by database corruption, a mismatched or incomplete prior upgrade that left objects in an inconsistent state, or a damaged master/mssqlsystemresource database preventing the script from resolving object references correctly. It can also occur if a previous failed patch or upgrade attempt was interrupted, leaving system catalog views or metadata out of sync.

Step-by-Step Resolution Guide

Step 1: Review the Full Error Log for the Root Cause

  • Open the SQL Server Error Log located at C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG.
  • Locate the error immediately preceding Error 917 — this will reference the specific line number and object that failed to compile.
  • Note the database name and script file (e.g., sqlagent100_msdb_upgrade.sql) mentioned in the message for targeted troubleshooting.

Step 2: Verify Database Consistency and Compatibility Level

  • Run DBCC CHECKDB('YourDatabaseName') WITH NO_INFOMSGS, ALL_ERRORS; in SQL Server Management Studio (SSMS) to rule out corruption.
  • Confirm the database compatibility level matches a supported level for SQL Server 2025 using:
  SELECT name, compatibility_level FROM sys.databases;
  • If compatibility level is outdated, update it with ALTER DATABASE YourDatabaseName SET COMPATIBILITY_LEVEL = 170;

Step 3: Restart Setup in Single-User Mode to Re-run Upgrade Scripts

  • Stop the SQL Server service via services.msc or PowerShell: Stop-Service MSSQLSERVER.
  • Restart the instance in single-user mode using Command Prompt:
  NET START MSSQLSERVER /m
  • Connect via sqlcmd -S . -E and manually inspect/re-run the failing upgrade script segment identified in Step 1.

Step 4: Restore from a Pre-Upgrade Backup if Corruption Persists

  • If DBCC CHECKDB reports unrepairable allocation or catalog errors, restore the affected database from the most recent known-good backup taken prior to the upgrade attempt.
  • Use SSMS Tasks > Restore > Database, or run:
  RESTORE DATABASE YourDatabaseName FROM DISK = 'D:\Backups\PreUpgrade.bak' WITH REPLACE;
  • Re-attempt the SQL Server 2025 upgrade/patch installation after confirming database integrity.

Alternative or Verification Steps

  • Confirm the fix by re-running Setup or the Cumulative Update installer and checking that the Summary.txt log (in %ProgramFiles%\Microsoft SQL Server\170\Setup Bootstrap\Log\) reports no further 917 errors.
  • If the issue persists only on msdb or master, consider rebuilding system databases using setup.exe /ACTION=REBUILDDATABASE as a last resort, followed by reapplying the latest Cumulative Update.