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

Why This Error Happens

Error 4065 occurs when a client application attempts to execute a procedure or function through the Open Data Services (ODS) layer that SQL Server does not recognize as a valid remote procedure call. This typically happens when a legacy extended stored procedure (xp_) or system procedure has been deprecated, renamed, or is being invoked with an incorrect calling convention from an ODBC/OLE DB driver. It can also surface when a third-party or custom application uses outdated driver libraries that attempt to call internal SQL Server procedures no longer exposed in SQL Server 2025.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Procedure Call

  • Check the SQL Server Error Log (C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG) for the exact procedure name substituted into '%.*ls'.
  • Run SELECT * FROM sys.sysmessages WHERE error = 4065; to confirm the message template and correlate it with the Event Viewer entry under Windows Logs > Application.
  • Cross-reference the procedure name against sys.objects to see if it still exists: SELECT name FROM sys.objects WHERE name = '<procedure_name>';

Step 2: Update Client Drivers and Connection Strings

  • Open ODBC Data Source Administrator (search odbcad32.exe on Windows Server 2025 / Windows 11) and verify the driver version is ODBC Driver 18 for SQL Server or later.
  • Update any legacy OLE DB provider (SQLOLEDB) references in connection strings to MSOLEDBSQL19.
  • Restart the dependent application pool or service in IIS Manager or Services.msc after updating the driver.

Step 3: Validate Extended Stored Procedure Permissions

  • Confirm the login has EXECUTE permission: GRANT EXECUTE ON <procedure_name> TO [DOMAIN\User];
  • If the procedure is a custom extended stored procedure (xp_), ensure its DLL is still registered under C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Binn\ and re-register it using sp_addextendedproc.
  • If the DLL is missing or corrupted, reinstall the component from the original vendor package.

Step 4: Enable Trace Flags for Deeper Diagnostics

  • Start SQL Server with trace flag 3656 to capture more verbose ODS call stack information:
  DBCC TRACEON (3656, -1);
  • Reproduce the error and review the enhanced log output in SQL Server Configuration Manager > SQL Server Logs.

Alternative or Verification Steps

  • Run DBCC TRACESTATUS(-1); to confirm active trace flags, then re-run the original application request to verify the error no longer appears in the SQL Server Error Log.
  • If the issue persists, use SQL Server Profiler (or Extended Events in SSMS) to capture the exact RPC call and compare it against Microsoft’s current list of supported system/extended stored procedures for SQL Server 2025, replacing any deprecated calls with their modern T-SQL equivalents.