Why This Error Happens
Error 13162 occurs within SQL Server’s Service Broker architecture when a conversation endpoint enters an error state that cannot be resolved through normal message exchange, forcing the engine to terminate it using the WITH CLEANUP option. This typically happens because the corresponding dialog on the remote endpoint has already been dropped, the message payload failed contract validation, or the sys.conversation_endpoints catalog view contains orphaned entries due to a crashed transaction. In Windows Server 2025 / Windows 11 environments, this is frequently exacerbated by antivirus or Windows Defender real-time scanning interfering with the .mdf/.ldf I/O operations that Service Broker relies on for transactional consistency.
Step-by-Step Resolution Guide
Step 1: Identify the Orphaned Conversation Handles
- Open SQL Server Management Studio (SSMS) and connect to the affected instance.
- Run the following query to locate endpoints stuck in an error state:
SELECT conversation_handle, far_service, state_desc, lifetime
FROM sys.conversation_endpoints
WHERE state_desc = 'ERROR';
- Note the
conversation_handleGUIDs returned; these are the sessions causing the 13162 event log entries.
Step 2: Force-Terminate the Problematic Dialogs
- For each handle identified in Step 1, execute a manual cleanup command to clear the queue:
END CONVERSATION 'handle-guid-here' WITH CLEANUP;
- If the command hangs, verify no active transactions are locking the
sys.transmission_queueby checkingsys.dm_tran_locks. - Run
DBCC CHECKDBon the specific database if cleanup fails repeatedly, as this often indicates underlying page corruption on the system tables.
Step 3: Adjust Windows Server Exclusions and Service Broker Settings
- Navigate to Windows Security > Virus & threat protection > Manage settings > Add or remove exclusions.
- Add the SQL Server data directory (typically
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA) to prevent I/O locks during the conversation handshake. - Restart the
SQL Server Service Brokerdependency by restarting the SQL Server service viaservices.mscto flush the transmission queue.
Step 4: Validate Network Timeout Configurations
- Check the
Dialog Timersettings within your Service Broker queue to ensure timeouts are not too aggressive for the network latency in Windows Server 2025 virtualized environments. - Update the
QUEUEdefinition to includeACTIVATIONprocedures that handleErrormessage types gracefully to prevent future forced cleanups.
Alternative or Verification Steps
- Verify the fix by re-running the
sys.conversation_endpointsquery from Step 1; the result set should return zero rows withstate_desc = 'ERROR'. - If the issue persists across reboots, check the SQL Server Error Log for Event ID 9675, which often precedes 13162 and points to a specific certificate or encryption mismatch between the initiator and target databases.