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

Troubleshooting Guide: SQL Server Error 5837 – Service Broker Listen Port Cannot Be Dynamic

Why This Error Happens

This error occurs when the ALTER DATABASE SET ENABLE_BROKER or CREATE ENDPOINT statement attempts to configure the Service Broker listener using a port value set to 0 or outside the valid TCP port range. SQL Server 2025 strictly requires a static port between 1024 and 32767 for Service Broker communication, as dynamic port allocation (used by protocols like named pipes) is not supported for this endpoint type. This typically happens due to a misconfigured connection string, a leftover default value from a migration script, or manual editing of endpoint metadata that introduced an invalid port number.

Step-by-Step Resolution Guide

Step 1: Identify the Current Broker Endpoint Configuration

  • Open SQL Server Management Studio (SSMS) and connect to the target instance on your Windows Server 2025 host.
  • Run the following query to inspect existing endpoints:
  SELECT name, port, protocol_desc, state_desc 
  FROM sys.tcp_endpoints;
  • Look for any NULL, 0, or out-of-range values in the port column associated with the SERVICE_BROKER protocol.

Step 2: Drop the Invalid Endpoint

  • If an invalid or dynamically-assigned endpoint exists, remove it before recreating it correctly.
  • Execute the following, replacing EndpointName with the actual name retrieved in Step 1:
  DROP ENDPOINT EndpointName;
  • Confirm no errors are returned and that the endpoint no longer appears in sys.tcp_endpoints.

Step 3: Recreate the Endpoint with a Valid Static Port

  • Choose an unused port within the 1024–32767 range (e.g., 4022, a common default for Service Broker).
  • Run the creation script explicitly defining the port:
  CREATE ENDPOINT ServiceBrokerEndpoint
  STATE = STARTED
  AS TCP (LISTENER_PORT = 4022)
  FOR SERVICE_BROKER (AUTHENTICATION = WINDOWS NEGOTIATE, ENCRYPTION = REQUIRED);
  • Ensure this port is not already bound by another application; check using netstat -ano | findstr "4022" in an elevated Command Prompt on Windows Server 2025.

Step 4: Open the Port in Windows Defender Firewall

  • Navigate to Windows Defender Firewall with Advanced Security on the server.
  • Create a new Inbound Rule for the specific TCP port (e.g., 4022) to allow SQL Server Service Broker traffic.
  • Restart the SQL Server (MSSQLSERVER) service via services.msc or by running net stop MSSQLSERVER && net start MSSQLSERVER in an elevated terminal.

Alternative or Verification Steps

  • Verify the fix by re-running SELECT * FROM sys.tcp_endpoints WHERE protocol = 'TCP'; and confirming the port column shows a static, valid integer (e.g., 4022) rather than NULL or 0.
  • If the error persists, check for duplicate Broker configurations across linked databases using SELECT name, is_broker_enabled FROM sys.databases; and ensure no conflicting GUID mismatches exist between the service_broker_guid values.