Always On AG secondary replicas showing DISCONNECTED despite endpoint and network checks passing

Gowtham K 0 Reputation points
2026-09-06T06:41:32.6166667+00:00

We are facing an issue with a SQL Server Always On Availability Group where the secondary replica remains DISCONNECTED. We have verified that the HADR endpoint is STARTED, uses TCP port 5022, and AES encryption. The SQL Server service accounts are running, and the required CONNECT permission is granted on the endpoint. Port 5022 connectivity was tested successfully in both directions using Test-NetConnection. The listener is reachable on port 1433 for one IP, while connectivity to another listener IP failed. DNS resolution is working, and port 5022 is listening under sqlservr.exe. No HADR-related certificates were found. What additional checks or resolution steps should we perform?User's image

SQL Server | Other
SQL Server | Other

Additional SQL Server features and topics not covered by specific categories


1 answer

Sort by: Most helpful
  1. AI answer

    2026-09-06T06:42:05.4166667+00:00

    Additional checks should focus on replica-to-replica endpoint configuration consistency and connection error details.

    1. Check the last HADR connection error on both primary and secondary replicas.
    SELECT r.replica_server_name,
           r.endpoint_url,
           rs.connected_state_desc,
           rs.last_connect_error_description,
           rs.last_connect_error_number,
           rs.last_connect_error_timestamp
    FROM sys.dm_hadr_availability_replica_states AS rs
         INNER JOIN sys.availability_replicas AS r
             ON rs.replica_id = r.replica_id
    WHERE rs.is_local = 1;
    

    This identifies the most recent connection failure. If the description shows DNS lookup failure or an incorrect host, the replica endpoint_url is likely wrong.

    1. Verify that the AG endpoint_url matches the actual database mirroring endpoint port on each replica.

    Run on the primary and each disconnected secondary:

    SELECT endpoint_url
    FROM sys.availability_replicas;
    

    Then verify the local endpoint definition:

    SELECT tep.name AS EndPointName,
           sp.name AS CreatedBy,
           tep.type_desc,
           tep.state_desc,
           tep.port
    FROM sys.tcp_endpoints AS tep
         INNER JOIN sys.server_principals AS sp
             ON tep.principal_id = sp.principal_id
    WHERE tep.type = 4;
    

    The port in endpoint_url must match the port defined for the endpoint on that replica. A mismatch can leave replicas in DISCONNECTED even when Test-NetConnection to 5022 succeeds.

    1. Recheck endpoint configuration on both replicas and compare encryption settings.
    $server_name = "server_instance"
    sqlcmd -S $server_name -E -Q "SELECT name, state_desc, encryption_algorithm_desc, protocol_desc, type_desc FROM sys.database_mirroring_endpoints"
    

    Run it on both servers and confirm the encryption and protocol values match.

    1. Confirm there is no port conflict despite sqlservr.exe listening on 5022.
    $server_name = "server_instance"
    sqlcmd -S $server_name -E -Q "SELECT type_desc, port FROM sys.tcp_endpoints WHERE type_desc = 'DATABASE_MIRRORING'; "
    
    $port = "5022"
    Get-NetTCPConnection -LocalPort $port
    Get-Process -Id (Get-NetTCPConnection -LocalPort $port).OwningProcess | Select-Object Name, ProductVersion, Path, Id
    

    This confirms the mirroring endpoint is bound to the expected port and helps detect another process or instance using that port.

    1. Validate connectivity by both server name and IP address for each replica endpoint.
    $server_name = "your_server_name"
    $IP_address = "your_ip_address"
    $port_number = "your_port_number"
    
    Test-NetConnection -ComputerName $server_name -Port $port_number
    Test-NetConnection -ComputerName $IP_address -Port $port_number
    

    Expected result is TcpTestSucceeded : True.

    • If IP works but server name fails, the issue is likely DNS or name resolution.
    • If server name works but IP fails, another endpoint or instance may be listening on that port.
    • If either fails intermittently, check firewall and, for Azure VMs, NSG rules.
    1. If the endpoint exists but may not be responding, restart the endpoint carefully.
    sqlcmd -S "server_instance" -E -Q "ALTER ENDPOINT hadr_endpoint STATE = stopped"
    sqlcmd -S "server_instance" -E -Q "ALTER ENDPOINT hadr_endpoint STATE = started"
    

    Warning: setting STATE = stopped temporarily interrupts Always On traffic flow.

    1. If SQL Server is running under an account that is not a domain user, test connectivity while signed in as that service account.
    • Open Windows PowerShell with Run as Different User.
    • Sign in with the SQL Server service account.
    • Run whoami to confirm the account.
    • Then test the remote node on port 5022 with Test-NetConnection.

    Given that one listener IP is reachable and another is not, also treat that as a sign to compare endpoint URLs, port bindings, and network path behavior per replica rather than assuming the AG endpoint is fully healthy because 5022 responds.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.