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

Troubleshooting Guide: SQL Server Error 4165 — “The score override argument…”

Why This Error Happens

Error 4165 typically occurs when the Query Optimizer’s automatic tuning feature (specifically the “score override” hint used in cardinality estimation or plan forcing) receives an invalid or out-of-range argument value. This is often triggered by corrupted Query Store data, malformed plan hints injected via OPTION clauses, or incompatible trace flags left over from a migration to SQL Server 2025. In some cases, it stems from a botched upgrade where legacy compatibility-level settings conflict with the new adaptive query processing engine.

Step-by-Step Resolution Guide

Step 1: Validate the Query and Hint Syntax

  • Open the offending query in SQL Server Management Studio (SSMS) 21 and check for any manually inserted OPTION (USE HINT(...)) or QUERYTRACEON clauses.
  • Remove any custom SCORE OVERRIDE or cardinality estimation hints temporarily to confirm they are the trigger.
  • Run the query in isolation using SET SHOWPLAN_XML ON to inspect the execution plan for malformed hint arguments.

Step 2: Clear and Rebuild Query Store Data

  • Navigate to Database Properties > Query Store in SSMS and set the operation mode to OFF temporarily.
  • Run the following command to purge corrupted plan data:
  ALTER DATABASE [YourDB] SET QUERY_STORE CLEAR;
  • Re-enable Query Store with ALTER DATABASE [YourDB] SET QUERY_STORE = ON; and allow it to rebuild baseline statistics.

Step 3: Verify Trace Flags and Compatibility Level

  • Check active trace flags using DBCC TRACESTATUS(-1); and disable any flags related to legacy cardinality estimation (e.g., 9481, 2312) that may conflict with SQL Server 2025’s native optimizer.
  • Confirm the database compatibility level matches SQL Server 2025 standards:
  ALTER DATABASE [YourDB] SET COMPATIBILITY_LEVEL = 170;
  • Restart the SQL Server service via services.msc on Windows Server 2025 to clear the plan cache fully.

Step 4: Update SQL Server Cumulative Updates

  • Go to Windows Update or the Microsoft Update Catalog and check for the latest Cumulative Update (CU) for SQL Server 2025, as this error is linked to a known optimizer bug patched in early CUs.
  • Install the update and reboot the server if prompted.

Alternative or Verification Steps

  • Re-run the original query that threw Error 4165 and confirm it executes without exceptions; check the SQL Server Error Log (Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log) for recurrence.
  • If the error persists, disable Automatic Tuning entirely via ALTER DATABASE [YourDB] SET AUTOMATIC_TUNING (FORCE_LAST_GOOD_PLAN = OFF); as a temporary workaround while awaiting a vendor patch.