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

Troubleshooting Guide: SQL Server Error 11222 — Service Broker TO Service Name Mismatch

Why This Error Happens

Error 11222 occurs when Service Broker detects that the TO Service Name specified in an incoming message does not match the TO Service Name originally recorded on the conversation endpoint when the dialog was established. This typically happens due to conversation handle reuse errors, application logic that incorrectly constructs a new message against a stale or unrelated endpoint, or corruption/mismatch in the sys.conversation_endpoints metadata caused by replication, mirroring, or improper endpoint cleanup. It can also surface when routing configurations or service broker GUIDs change after a database restore, causing message routing to resolve to an endpoint that no longer matches the service contract.

Step-by-Step Resolution Guide

Step 1: Identify the Affected Conversation Endpoints

  • Run the following query to locate the problematic conversation handles:
  SELECT conversation_handle, far_service, service_name, state_desc 
  FROM sys.conversation_endpoints 
  WHERE state_desc <> 'CLOSED';
  • Cross-reference far_service with the TO Service Name reported in the error message text to confirm the mismatch.
  • Check SQL Server Error Log (C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG) for repeated occurrences and timestamps correlating with application activity.

Step 2: Validate Application Code for Conversation Handle Reuse

  • Audit the application or stored procedure logic (commonly in SEND ON CONVERSATION statements) to ensure a new BEGIN DIALOG CONVERSATION is issued per unique target service rather than reusing a cached conversation handle.
  • Confirm that conversation handles are not being persisted across sessions or threads in multi-threaded .NET or Service Broker listener applications.
  • Review any custom routing tables via sys.routes to ensure the ADDRESS and SERVICE NAME values align with the actual broker service definitions.

Step 3: Clean Up Stale or Corrupted Conversation Endpoints

  • End any orphaned or inconsistent conversations manually:
  END CONVERSATION 'conversation_handle_guid' WITH CLEANUP;
  • Restart the affected Service Broker queue to clear cached routing information:
  ALTER QUEUE [QueueName] WITH STATUS = OFF;
  ALTER QUEUE [QueueName] WITH STATUS = ON;
  • If the issue surfaced after a database restore or mirroring failover, regenerate the Service Broker GUID only if necessary using ALTER DATABASE [DBName] SET NEW_BROKER WITH ROLLBACK IMMEDIATE (use with caution, as this breaks all existing conversations).

Step 4: Verify Service and Contract Definitions

  • Confirm that sys.services and sys.service_contracts have matching, non-ambiguous service names across all participating databases.
  • Ensure no duplicate service names exist on the same broker instance, which can cause SQL Server to resolve the TO Service Name to the wrong endpoint.
  • On Windows Server 2025/Windows 11 hosts, verify no network-level load balancer or proxy is duplicating/rewriting TDS packets in a way that scrambles Service Broker message routing.

Alternative or Verification Steps

  • After applying fixes, enable Service Broker diagnostic tracing using Extended Events (sqlserver.broker_conversation and sqlserver.broker_message_classify) to confirm new conversations resolve to the correct TO Service Name without errors.
  • If the error persists despite clean endpoints, consider dropping and recreating the affected Service Broker service and queue objects entirely, then re-test message delivery with a fresh BEGIN DIALOG CONVERSATION to rule out residual metadata corruption.