Additional SQL Server features and topics not covered by specific categories
Additional checks should focus on replica-to-replica endpoint configuration consistency and connection error details.
- 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.
- Verify that the AG
endpoint_urlmatches 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.
- 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.
- Confirm there is no port conflict despite
sqlservr.exelistening 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.
- 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.
- 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.
- 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
whoamito 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: