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

Troubleshooting Guide: SQL Server Error 4124 — “The Parameters Supplied for the Batch Are Not Valid”

Why This Error Happens

Error 4124 typically occurs when SQL Server 2025 receives a parameterized batch request (often via sp_executesql, ODBC, or OLE DB providers) where the parameter definitions do not match the actual data types, lengths, or count expected by the query engine. This mismatch is frequently caused by outdated client drivers, corrupted connection metadata, or application code that dynamically builds parameter arrays incorrectly. In some cases, this is triggered after an in-place upgrade to Windows Server 2025 or Windows 11 where legacy driver versions (such as older ODBC Driver 17) remain cached and conflict with the new TDS protocol version used by SQL Server 2025.

Step-by-Step Resolution Guide

Step 1: Verify and Update the Client Driver

  • Open ODBC Data Source Administrator (64-bit) via odbcad32.exe and check the driver version under the “Drivers” tab.
  • Ensure you are running Microsoft ODBC Driver 18 for SQL Server or later, which fully supports the TDS 8.0 protocol used in SQL Server 2025.
  • Uninstall older drivers via Settings > Apps > Installed Apps to prevent version conflicts.
  • Reinstall the latest driver package from the official Microsoft Download Center.

Step 2: Inspect the Parameterized Query Syntax

  • Open the failing stored procedure or query in SQL Server Management Studio (SSMS) 21.
  • Check for mismatched parameter counts between the sp_executesql call and the @params definition string.
  • Example of a common error:
  EXEC sp_executesql N'SELECT * FROM Orders WHERE OrderID = @ID', N'@ID int', @ID = '12345'
  • Ensure the data type passed (e.g., varchar) matches the data type declared (e.g., int).

Step 3: Clear Cached Execution Plans

  • Corrupted or stale execution plans can cause SQL Server to misinterpret parameter sniffing data.
  • Run the following command in a New Query window to clear the specific plan cache:
  DBCC FREEPROCCACHE;
  • If the issue persists only for a specific database, use ALTER DATABASE [YourDB] SET PARAMETERIZATION SIMPLE; to test if forced parameterization is the root cause.

Step 4: Check Windows Server 2025 Security Policies

  • Navigate to Control Panel > Administrative Tools > Local Security Policy.
  • Verify that the “Network Security: Minimum session security for NTLM SSP based clients” setting hasn’t blocked specific encryption methods required by the new driver handshake.
  • Restart the SQL Server (MSSQLSERVER) service via services.msc after any policy changes.

Alternative or Verification Steps

  • Verification: Run the specific failing query directly in SSMS using hardcoded values instead of parameters. If it succeeds, the issue is confirmed to be in the parameter-passing logic of the client application rather than the database engine itself.
  • Alternative Fix: If the error persists only on Windows 11 client machines, temporarily switch the connection string from “Encrypt=Mandatory” to “Encrypt=Optional” to rule out a TLS/SSL handshake issue interfering with the parameter payload.