Skip to content
Microsoft SQL Server

SQL Server Error 35250

The connection to the primary replica is not active

Severity 16 High Availability
Applies to: SQL Server 2016 to 2025 with Always On availability groups (including distributed availability groups)
Last technically reviewed 23 October 2026 on SQL Server 2025 (17.0.1145.4)
The full message
The connection to the primary replica is not active. The command cannot be processed.
Error number
35250
Severity
16 (user-correctable error)
State
Not documented by Microsoft (not reproduced here)
Product
Microsoft SQL Server Database Engine
Versions
SQL Server 2016 to 2025 with Always On availability groups (including distributed availability groups)
Last reviewed
23 October 2026

What it means

Error 35250 means a secondary replica could not talk to the primary replica through the availability group endpoint, so a command that needs the primary (typically joining a database to the group) was refused.

Replicas in an availability group talk to each other over the database mirroring endpoint (TCP port 5022 by default), not over the normal client port. When you join a secondary database, or run another command that needs the primary, the secondary checks its connection to the primary first. If that connection is not established, it raises 35250. Microsoft documents this mainly for joining secondary databases when the endpoint cannot be reached.

So the message is about server-to-server networking and security, not about your own connection: you can be connected to both servers in SSMS and still get it. The real cause is usually recorded in sys.dm_hadr_availability_replica_states (last_connect_error_description) and in the error log on both replicas, for example a DNS lookup failure, a blocked port or an endpoint login that is refused.

Common causes

  • The endpoint port (5022 by default) is blocked by a Windows firewall, network firewall or cloud security group between the replicas, in either direction.
  • The endpoint_url defined for a replica has the wrong host name, IP address or port, or the name does not resolve correctly (DNS or a stale HOSTS file entry).
  • The database mirroring endpoint is stopped, or another process or instance holds the port.
  • The service account of the other replica has no CONNECT permission on the endpoint (or the certificates used for endpoint authentication do not match).
  • The replicas are still connecting after a restart or failover, or a known product issue fixed in a later cumulative update.

Diagnose it

Read-only These queries only read metadata and dynamic management views. They do not change data, permissions or configuration, so they are safe to run first.

What does the replica report as its last connection error?

Run it on the secondary and on the primary (from Microsoft's MSSQLSERVER_35250 guidance).

SELECT r.replica_server_name, r.endpoint_url, rs.role_desc, rs.connected_state_desc,
       rs.last_connect_error_number, rs.last_connect_error_description,
       rs.last_connect_error_timestamp
FROM sys.dm_hadr_availability_replica_states AS rs
JOIN sys.availability_replicas AS r ON rs.replica_id = r.replica_id;
What to look for

DISCONNECTED with a description such as DNS Lookup failed with error '11001(No such host is known)' points straight at the cause. Check that each endpoint_url names the right host and port.

Is the endpoint started, and on which port?

SELECT e.name, e.state_desc, e.role_desc, t.port, t.ip_address,
       e.connection_auth_desc, e.encryption_algorithm_desc
FROM sys.database_mirroring_endpoints AS e
JOIN sys.tcp_endpoints AS t ON t.endpoint_id = e.endpoint_id;
What to look for

state_desc must be STARTED on every replica, and port must match the port in that replica's endpoint_url.

Who has CONNECT permission on the endpoint?

SELECT ep.name AS endpoint_name, pr.name AS grantee, pr.type_desc,
       pe.permission_name, pe.state_desc
FROM sys.server_permissions AS pe
JOIN sys.endpoints AS ep ON ep.endpoint_id = pe.major_id
JOIN sys.server_principals AS pr ON pr.principal_id = pe.grantee_principal_id
WHERE pe.class_desc = N'ENDPOINT' AND ep.type = 4;
What to look for

The service account of every other replica (or the login mapped to its certificate) should be listed with CONNECT and GRANT.

Look for endpoint errors in the error log

EXEC sp_readerrorlog 0, 1, N'endpoint';
What to look for

Handshake failures, refused logins on the endpoint, or a port that could not be opened. Read the log on both replicas.

How to fix it

Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.

Test the endpoint port from each replica to the other

Read-only

From the secondary to the primary and back, test the endpoint port. TcpTestSucceeded : True means the port is reachable. If the IP address works but the name does not, it is a name resolution problem; if neither works, look at firewalls and security groups.

# PowerShell on each replica
Test-NetConnection -ComputerName SQL01.contoso.com -Port 5022
Resolve-DnsName -Name SQL01.contoso.com

Open the endpoint port between the replicas

Changes configuration

Allow inbound TCP on the endpoint port on every replica, only from the other replicas, in Windows Firewall and in any network firewall or cloud security group in between.

Correct the endpoint URL or start the endpoint

Changes configuration

If an endpoint_url is wrong, correct it on the primary. If the endpoint is stopped, start it. Microsoft warns that restarting an endpoint can cause a short interruption for the replica.

Caution: Stopping or restarting an endpoint briefly disconnects that replica from the group. Do it in a quiet period, never on the primary while it is serving production without a plan.

ALTER AVAILABILITY GROUP SalesAg
MODIFY REPLICA ON N'SQL02'
WITH (ENDPOINT_URL = N'TCP://SQL02.contoso.com:5022');

-- on a replica whose endpoint is stopped
ALTER ENDPOINT Hadr_endpoint STATE = STARTED;

Grant CONNECT on the endpoint to the partner service account

Changes permissions

When replicas run under different domain accounts, each replica needs a login for the other replica's service account with CONNECT on its endpoint. Grant only CONNECT on the endpoint; no server role is needed.

GRANT CONNECT ON ENDPOINT::Hadr_endpoint TO [CONTOSO\svc_sql02];

Examples

Joining a secondary database when the primary cannot be reached

Shown as documented by Microsoft (MSSQLSERVER_35250); not reproduced here because it needs an availability group. The state is the commonly reported one. The statement runs on the secondary replica after the database was restored there WITH NORECOVERY.

-- On the secondary replica SQL02
ALTER DATABASE SalesDb SET HADR AVAILABILITY GROUP = SalesAg;
Result
The connection to the primary replica is not active. The command cannot be processed.

How to prevent it

Before creating an availability group, test the endpoint port and name resolution in both directions between every pair of replicas, and script the endpoints, logins and CONNECT grants so every replica is set up the same way. Use fully qualified names in endpoint URLs.

Monitor connected_state_desc and last_connect_error_description for every replica, so a broken replica connection is found before a join or a failover depends on it.

Common questions

I can connect to both servers in SSMS. Why is the connection not active?

SSMS uses the client port (1433 by default). Replicas talk over the mirroring endpoint, usually port 5022, as the SQL Server service accounts. That path can be blocked or refused while client connections work.

Do I need to restart SQL Server to fix 35250?

Usually not. Fix the network, endpoint URL, endpoint state or CONNECT permission, then retry the join. Restarting an endpoint is sometimes needed, which is much smaller than a service restart.

Is 35250 the same as error 1418?

They have similar causes (an unreachable endpoint), but 1418 is raised when a mirroring partner or replica address cannot be reached, while 35250 is raised on a secondary that has no active connection to the primary.

Learn more on CodeWithSQL

Official documentation

Last technically reviewed 23 October 2026; examples and diagnostics run on SQL Server 2025 (17.0.1145.4). Message text checked against the engine's sys.messages catalogue.

Still stuck on a SQL Server error?

Browse the full SQL Server error library, or get hands-on help from an experienced SQL professional.