Troubleshooting Guide: SQL Server Error 11223 — Service Broker Contract Mismatch
Why This Error Happens
This error occurs when a Service Broker message is sent using a service contract name that does not match the contract name bound to the existing conversation endpoint, typically because the sending application or stored procedure referenced an incorrect or outdated contract during a SEND operation. It can also arise after a service or contract has been altered or dropped and recreated with a different name, leaving stale conversation handles that still point to the old contract definition. In some cases, this is caused by mismatched Service Broker route or service definitions between the initiating and target databases, especially after a migration to SQL Server 2025 on Windows Server 2025.
Step-by-Step Resolution Guide
Step 1: Identify the Mismatched Contract and Conversation Endpoint
- Query
sys.conversation_endpointsto find the conversation handle generating the error:
SELECT conversation_handle, service_contract_name, far_service, state_desc
FROM sys.conversation_endpoints;
- Cross-reference the
service_contract_namecolumn with the contract name used in your application’sSENDstatement. - Note the exact contract names reported in the error message (both the message’s contract and the endpoint’s contract).
Step 2: Verify Service and Contract Definitions
- Run the following to confirm the current contract bound to the service:
SELECT s.name AS service_name, c.name AS contract_name
FROM sys.services AS s
JOIN sys.service_contract_usages AS scu ON s.service_id = scu.service_id
JOIN sys.service_contracts AS c ON scu.service_contract_id = c.service_contract_id;
- Confirm that the contract referenced in your
BEGIN DIALOG CONVERSATION ... ON CONTRACTstatement matches the one currently bound to the target service. - If the service was recently altered, update the application code or stored procedure to reference the correct, current contract name.
Step 3: End Stale Conversations and Restart the Dialog
- Terminate any conversations using the outdated contract reference:
END CONVERSATION 'conversation_handle_here' WITH CLEANUP;
- Restart the dialog using
BEGIN DIALOG CONVERSATIONwith the correct, verified contract name on both the initiator and target databases. - Ensure both databases involved in the conversation (especially in cross-database or cross-instance Broker setups) have synchronized contract and message type definitions.
Step 4: Rebuild Service Broker Objects if Corruption Is Suspected
- If contract definitions appear inconsistent or corrupted, drop and recreate the service, contract, and message type objects in the correct dependency order:
DROP SERVICE [YourServiceName];
DROP CONTRACT [YourContractName];
DROP MESSAGE TYPE [YourMessageType];
- Recreate them using a single, version-controlled script to avoid future naming mismatches.
- Re-enable Service Broker on the database if it was disabled during this process:
ALTER DATABASE [YourDatabase] SET ENABLE_BROKER;
Alternative or Verification Steps
- After applying fixes, send a test message through the corrected dialog and confirm it is received without errors by checking
sys.transmission_queuefor stuck or failed messages (an empty result indicates successful delivery). - If the issue persists across a linked or mirrored environment, verify that Service Broker routes (
sys.routes) and remote service bindings use identical contract names on all participating SQL Server 2025 instances.