Troubleshooting Guide: SQL Server Error 9616 – XML Validation Failure in Service Broker Messages
Why This Error Happens
Error 9616 occurs when Service Broker receives a message that does not conform to the XML schema expected for that message type, typically because the message body is malformed, truncated, or was generated by an application using an outdated or mismatched contract definition. This can also result from encoding mismatches (e.g., UTF-16 vs UTF-8) between the sender and receiver endpoints, or from corruption introduced during message transmission across linked SQL Server instances. In some cases, the issue stems from a message type incorrectly configured as VALIDATION = WELL_FORMED_XML or VALIDATION = VALID_XML WITH SCHEMA COLLECTION when the sending application never intended to send strict XML.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Conversation and Message
- Run the following query to pull details on the failed conversation using the Conversation ID from the error message:
SELECT conversation_handle, far_service, message_type_name, state_desc
FROM sys.conversation_endpoints
WHERE conversation_id = 'PASTE-CONVERSATION-ID-HERE';
- Check the Service Broker transmission queue for the raw message body:
SELECT * FROM sys.transmission_queue
WHERE conversation_handle = 'PASTE-CONVERSATION-HANDLE-HERE';
- Inspect the
transmission_statuscolumn for additional clues alongside the 9616 error.
Step 2: Validate the Message Type and Schema Collection Definition
- Query the current validation setting on the message type:
SELECT name, validation, validation_desc
FROM sys.service_message_types
WHERE name = 'YourMessageTypeName';
- If
validation_descreturnsVALID_XML WITH SCHEMA COLLECTION, verify the schema collection still matches the application’s payload structure:
SELECT xml_collection_id, name
FROM sys.xml_schema_collections
WHERE name = 'YourSchemaCollectionName';
- If the application has changed its payload structure, update the schema collection using
ALTER XML SCHEMA COLLECTIONto reflect the new XSD.
Step 3: Capture and Inspect the Raw Payload
- Use SQL Server Profiler or Extended Events (
Broker:Message ClassifyandBroker:Conversationevents) to capture the exact XML payload being sent. - Copy the captured XML into a validator (e.g., Visual Studio XML Editor or
xmllinton Windows Server 2025 via WSL) to pinpoint the exact line/node causing the schema mismatch. - Check for BOM (Byte Order Mark) issues or encoding mismatches — SQL Server Service Broker expects UTF-16 encoded XML by default unless explicitly cast.
Step 4: Correct the Application or Contract Configuration
- If the sending application is generating malformed XML, update the serialization logic (e.g., ensure proper namespace declarations and closing tags).
- If the message type was configured too strictly, consider relaxing validation temporarily for diagnosis:
ALTER MESSAGE TYPE YourMessageTypeName
VALIDATION = WELL_FORMED_XML;
- Redeploy the corrected application build or stored procedure that constructs the XML message body, then resend a test message through the same service/contract.
Step 5: Clear Poisoned Queues and Restart Broker Activity
- If the queue has entered a poison message state (5 consecutive failures), re-enable it manually:
ALTER QUEUE YourQueueName WITH STATUS = ON;
- Restart the SQL Server Broker task if conversations remain stuck:
ALTER DATABASE YourDatabaseName SET DISABLE_BROKER;
ALTER DATABASE YourDatabaseName SET ENABLE_BROKER;
- Monitor the SQL Server error log (
Windows Server 2025path:C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG) for recurrence of Error 9616 after the fix.
Alternative or Verification Steps
- Send a manual test message through
sys.sp_send_messageusing a known-valid XML payload to confirm the schema collection and validation settings now accept correctly formed messages. - If errors persist across all message types, consider temporarily dropping schema validation entirely (
VALIDATION = NONE) as a diagnostic fallback to isolate whether the issue is XML-specific or a deeper transport/encoding problem on the Windows Server 2025 network stack.