Create Availability Group Fails With Error 35250 'Failed to join the database'

Published Jan 15 2019 03:27 PM 4,845 Views
Microsoft
First published on MSDN on Dec 09, 2013

You can create an availability group using the New Availability Group wizard or using a series of transact-sql commands. A common failure can occur when attempting to create an availability group using either method. The error is as follows and is caused because the target primary and secondary replicas are unable to communicate:


Msg 35250, Level 16, State 7, Line 1
The connection to the primary replica is not active.  The command cannot be processed.


If creating the availability group using the New Availability Group wizard, the 'Joining <availability database> to availability group <availability group> at <replica>' will fail. Clicking the Error link, message 35250 is reported:



If you used transact-sql to create the availability group instead of the New Availability Group wizard, the ALTER DATABASE...SET HADR AVAILABILITY GROUP... command fails with message 35250:



Following is a list of common causes for this failure and steps to diagnose each.


Reason - Inbound Port 5022 Traffic is Blocked


IMPORTANT : By default, AlwaysOn configures the database mirroring endpoints to use port 5022, and the following document will use 5022 when discussing the database mirroring endpoint in use for availability groups. However, this may not be the configured port for the database mirroring endpoints in your environment.  Query sys.tcp_endpoints on each replica to confirm which port is being used:


select name, type, port from sys.tcp_endpoints where type_desc='database_mirroring'
go


By default inbound traffic is blocked in Windows firewall.



Port 5022 is used by the primary and secondary replicas for synchronization and communication purposes. Traffic must be allowed inbound on this port. Testing has shown that if port 5022 inbound traffic is blocked at the primary, at the secondary or at both, you will be unable to create the availability group and message 35250 will be reported.


Reason - Endpoint is not created or started


Ensure the mirroring endpoints are created and started on the primary and the secondary replicas.



To detect if the endpoints are created, query for database_mirroring endpoints at the primary and the secondary.


:Connect SQLNODE1
select name, state_desc, port from sys.tcp_endpoints where type_desc='DATABASE_MIRRORING'
go
:Connect SQLNODE2
select name, state_desc, port from sys.tcp_endpoints where type_desc='DATABASE_MIRRORING'
go


If you find an endpoint does not exist, create it:


:Connect SQLNODE1
create endpoint [Hadr_endpoint]
state=started
as tcp (listener_port = 5022, listener_ip = all)
for database_mirroring (role = all, authentication = windows negotiate, encryption = required algorithm aes)
go


To detect if the endpoints are started, query them at the primary and the secondary.


:Connect SQLNODE1
select name, state_desc, port FROM sys.tcp_endpoints where name='hadr_endpoint'
go
:Connect SQLNODE2
select name, state_desc, port from sys.tcp_endpoints where name='hadr_endpoint'
go


If you find an endpoint is not running, start it:


:Connect SQLNODE1
alter endpoint [Hadr_endpoint] state = started


IMPORTANT : There is a known issue in which sys.tcp_endpoints.state_desc may incorrectly report the endpoint as STARTED when it is not started. It is a good idea to execute the ALTER ENDPOINT command for the endpoint at each replica, despite the report given by sys.tcp_endpoints, queried above.


Reason - Endpoint permissions


If database mirroring endpoints are configured to use Windows authentication, ensure that the SQL Server instances hosting your availability replicas run with a SQL Server startup account are domain accounts.


The New Availability Group wizard catches this misconfiguration, and reports it. Note that the Endpoints tab is displayed and the SQL Server Service Account reports that one of the replica's startup account is configured for LocalSystem.



If you proceed by clicking Yes and complete the wizard, it will fail during the 'Joining <availability database> to availability group <availability group> at <replica>.'


If you are attempting to create an availability group using transact-sql, this configuration problem will not be detected and command ALTER DATABASE...SET HADR AVAILABILITY GROUP...  will fail with 35250.


Reason - SQL Server is not listening on port 5022


If SQL Server is unable to listen on port 5022, the New Availability Group wizard and the transact-sql command ALTER DATABASE...SET HADR AVAILABILITY GROUP...  will fail with 35250.


To determine if SQL Server is listening on port 5022, review the SQL Server error log. You should find the following message(s) in the SQL Server error log:


2013-12-09 08:52:25.47 spid23s     Server is listening on [ 'any' <ipv6> 5022].
2013-12-09 08:52:25.47 spid23s     Server is listening on [ 'any' <ipv4> 5022].


SQL Server may not be able to listen on port 5022 if another application is already listening on the port. If you find that SQL Server is not listening on port 5022 because it is already being used, run 'netstat -a' to determine what application is using the port:


Additional diagnostics - query sys.dm_hadr_availability_replica_states on the secondary


If the above settings check out, query the sys.dm_hadr_availability_replica_states for the last_connect_error_number which may help you diagnose the join issue. Depending on which replica was having difficulty communicating, you should query both the primary and secondary for the local replica:


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 rs join sys.availability_replicas r
on rs.replica_id=r.replica_id
where rs.is_local=1


For example, if the secondary was unable to communicate with the DNS server or if a replica's endpoint_url was configured incorrectly when creating the availability group, you may get the following results:







%3CLINGO-SUB%20id%3D%22lingo-sub-317987%22%20slang%3D%22en-US%22%3ECreate%20Availability%20Group%20Fails%20With%20Error%2035250%20'Failed%20to%20join%20the%20database'%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-317987%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Dec%2009%2C%202013%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EYou%20can%20create%20an%20availability%20group%20using%20the%20New%20Availability%20Group%20wizard%20or%20using%20a%20series%20of%20transact-sql%20commands.%20A%20common%20failure%20can%20occur%20when%20attempting%20to%20create%20an%20availability%20group%20using%20either%20method.%20The%20error%20is%20as%20follows%20and%20is%20caused%20because%20the%20target%20primary%20and%20secondary%20replicas%20are%20unable%20to%20communicate%3A%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EMsg%2035250%2C%20Level%2016%2C%20State%207%2C%20Line%201%20%3CBR%20%2F%3E%20The%20connection%20to%20the%20primary%20replica%20is%20not%20active.%26nbsp%3B%20The%20command%20cannot%20be%20processed.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EIf%20creating%20the%20availability%20group%20using%20the%20New%20Availability%20Group%20wizard%2C%20the%20'Joining%20%3CAVAILABILITY%20database%3D%22%22%3E%20to%20availability%20group%20%3CAVAILABILITY%20group%3D%22%22%3E%20at%20%3CREPLICA%3E'%20will%20fail.%20Clicking%20the%20Error%20link%2C%20message%2035250%20is%20reported%3A%3C%2FREPLICA%3E%3C%2FAVAILABILITY%3E%3C%2FAVAILABILITY%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67834iA341FA42AFDE0104%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EIf%20you%20used%20transact-sql%20to%20create%20the%20availability%20group%26nbsp%3Binstead%20of%20the%20New%20Availability%20Group%20wizard%2C%20the%20ALTER%20DATABASE...SET%20HADR%20AVAILABILITY%20GROUP...%20command%20fails%20with%20message%2035250%3A%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67836iCFB602D3720B0018%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EFollowing%20is%20a%20list%20of%20common%20causes%20for%20this%20failure%20and%20steps%20to%20diagnose%20each.%3C%2FP%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId-1477837758%22%20id%3D%22toc-hId-1593329717%22%3EReason%26nbsp%3B-%20Inbound%20Port%205022%20Traffic%20is%20Blocked%3C%2FH3%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3EIMPORTANT%20%3C%2FSTRONG%3E%20%3A%20By%20default%2C%20AlwaysOn%20configures%20the%20database%20mirroring%20endpoints%20to%20use%20port%205022%2C%20and%20the%20following%20document%20will%20use%205022%20when%20discussing%20the%20database%20mirroring%20endpoint%20in%20use%20for%20availability%20groups.%20However%2C%26nbsp%3Bthis%20may%20not%20be%20the%20configured%20port%20for%20the%20database%20mirroring%20endpoints%20in%20your%20environment.%26nbsp%3B%20Query%20sys.tcp_endpoints%20on%20each%20replica%26nbsp%3Bto%20confirm%20which%20port%20is%20being%20used%3A%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eselect%20name%2C%20type%2C%20port%20from%20sys.tcp_endpoints%20where%20type_desc%3D'database_mirroring'%20%3CBR%20%2F%3E%20go%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EBy%20default%20inbound%20traffic%20is%20blocked%20in%20Windows%20firewall.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67838iF55A58F8CD23F053%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EPort%205022%20is%20used%20by%20the%20primary%20and%20secondary%20replicas%20for%20synchronization%20and%20communication%20purposes.%20Traffic%20must%20be%20allowed%20inbound%20on%20this%20port.%20Testing%20has%20shown%20that%20if%20port%205022%20inbound%20traffic%20is%20blocked%20at%20the%20primary%2C%20at%20the%20secondary%20or%20at%20both%2C%20you%20will%20be%20unable%20to%20create%20the%20availability%20group%20and%20message%2035250%20will%20be%20reported.%3C%2FP%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId--1074319203%22%20id%3D%22toc-hId--958827244%22%3EReason%20-%20Endpoint%20is%20not%20created%20or%20started%3C%2FH3%3E%3CBR%20%2F%3E%3CP%3EEnsure%20the%20mirroring%20endpoints%26nbsp%3Bare%20created%20and%20started%20on%20the%20primary%20and%20the%20secondary%20replicas.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67840iED5152E590292747%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ETo%20detect%20if%20the%20endpoints%20are%20created%2C%20query%20for%20database_mirroring%20endpoints%20at%20the%20primary%20and%20the%20secondary.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3AConnect%20SQLNODE1%20%3CBR%20%2F%3E%20select%20name%2C%20state_desc%2C%20port%20from%20sys.tcp_endpoints%20where%20type_desc%3D'DATABASE_MIRRORING'%20%3CBR%20%2F%3E%20go%20%3CBR%20%2F%3E%20%3AConnect%20SQLNODE2%20%3CBR%20%2F%3E%20select%20name%2C%20state_desc%2C%20port%20from%20sys.tcp_endpoints%20where%20type_desc%3D'DATABASE_MIRRORING'%20%3CBR%20%2F%3E%20go%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EIf%20you%20find%20an%20endpoint%26nbsp%3Bdoes%20not%20exist%2C%20create%20it%3A%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3AConnect%20SQLNODE1%20%3CBR%20%2F%3E%20create%20endpoint%20%5BHadr_endpoint%5D%20%3CBR%20%2F%3E%20state%3Dstarted%20%3CBR%20%2F%3E%20as%20tcp%20(listener_port%20%3D%205022%2C%20listener_ip%20%3D%20all)%20%3CBR%20%2F%3E%20for%20database_mirroring%20(role%20%3D%20all%2C%20authentication%20%3D%20windows%20negotiate%2C%20encryption%20%3D%20required%20algorithm%20aes)%20%3CBR%20%2F%3E%20go%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ETo%20detect%20if%20the%20endpoints%20are%20started%2C%20query%20them%20at%20the%20primary%20and%20the%20secondary.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3AConnect%20SQLNODE1%20%3CBR%20%2F%3E%20select%20name%2C%20state_desc%2C%20port%20FROM%20sys.tcp_endpoints%20where%20name%3D'hadr_endpoint'%20%3CBR%20%2F%3E%20go%20%3CBR%20%2F%3E%20%3AConnect%20SQLNODE2%20%3CBR%20%2F%3E%20select%20name%2C%20state_desc%2C%20port%20from%20sys.tcp_endpoints%20where%20name%3D'hadr_endpoint'%20%3CBR%20%2F%3E%20go%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EIf%20you%20find%20an%20endpoint%26nbsp%3Bis%20not%20running%2C%20start%20it%3A%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3AConnect%20SQLNODE1%20%3CBR%20%2F%3E%20alter%20endpoint%20%5BHadr_endpoint%5D%20state%20%3D%20started%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CSTRONG%3EIMPORTANT%20%3C%2FSTRONG%3E%20%3A%20There%20is%20a%20known%20issue%20in%20which%20sys.tcp_endpoints.state_desc%20may%20incorrectly%20report%20the%20endpoint%20as%20STARTED%20when%20it%20is%20not%20started.%20It%20is%20a%20good%20idea%20to%20execute%20the%20ALTER%20ENDPOINT%20command%20for%20the%20endpoint%20at%20each%20replica%2C%20despite%20the%20report%20given%20by%20sys.tcp_endpoints%2C%20queried%20above.%3C%2FP%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId-668491132%22%20id%3D%22toc-hId-783983091%22%3EReason%20-%20Endpoint%20permissions%3C%2FH3%3E%3CBR%20%2F%3E%3CP%3EIf%20database%20mirroring%20endpoints%20are%20configured%20to%20use%20Windows%20authentication%2C%20ensure%20that%20the%20SQL%20Server%20instances%20hosting%20your%20availability%20replicas%20run%20with%20a%20SQL%20Server%20startup%20account%20are%20domain%20accounts.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThe%20New%20Availability%20Group%20wizard%20catches%20this%20misconfiguration%2C%20and%20reports%20it.%20Note%20that%20the%20Endpoints%20tab%20is%20displayed%20and%20the%20SQL%20Server%20Service%20Account%20reports%20that%20one%20of%20the%20replica's%20startup%20account%26nbsp%3Bis%20configured%20for%20LocalSystem.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67842i2F8047F32AF5CB63%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EIf%20you%20proceed%20by%20clicking%20Yes%20and%20complete%20the%20wizard%2C%20it%20will%20fail%20during%20the%20'Joining%20%3CAVAILABILITY%20database%3D%22%22%3E%20to%20availability%20group%20%3CAVAILABILITY%20group%3D%22%22%3E%20at%20%3CREPLICA%3E.'%3C%2FREPLICA%3E%3C%2FAVAILABILITY%3E%3C%2FAVAILABILITY%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EIf%20you%20are%20attempting%20to%20create%20an%20availability%20group%20using%20transact-sql%2C%20this%20configuration%20problem%20will%20not%20be%20detected%20and%20command%20ALTER%20DATABASE...SET%20HADR%20AVAILABILITY%20GROUP...%26nbsp%3B%20will%20fail%20with%2035250.%3C%2FP%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId--1883665829%22%20id%3D%22toc-hId--1768173870%22%3EReason%20-%20SQL%20Server%20is%20not%20listening%20on%20port%205022%3C%2FH3%3E%3CBR%20%2F%3E%3CP%3EIf%20SQL%20Server%20is%20unable%20to%20listen%20on%20port%205022%2C%20the%20New%20Availability%20Group%20wizard%20and%20the%20transact-sql%20command%20ALTER%20DATABASE...SET%20HADR%20AVAILABILITY%20GROUP...%26nbsp%3B%20will%20fail%20with%2035250.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ETo%20determine%20if%20SQL%20Server%20is%20listening%20on%20port%205022%2C%20review%20the%20SQL%20Server%20error%20log.%20You%20should%20find%20the%20following%20message(s)%20in%20the%20SQL%20Server%20error%20log%3A%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E2013-12-09%2008%3A52%3A25.47%20spid23s%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Server%20is%20listening%20on%20%5B%20'any'%20%3CIPV6%3E%205022%5D.%20%3CBR%20%2F%3E%202013-12-09%2008%3A52%3A25.47%20spid23s%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20Server%20is%20listening%20on%20%5B%20'any'%20%3CIPV4%3E%205022%5D.%3C%2FIPV4%3E%3C%2FIPV6%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3ESQL%20Server%20may%20not%20be%20able%20to%20listen%20on%20port%205022%20if%20another%20application%20is%20already%20listening%20on%20the%20port.%20If%20you%20find%20that%20SQL%20Server%20is%20not%20listening%20on%20port%205022%20because%20it%20is%20already%20being%20used%2C%20run%20'netstat%20-a'%26nbsp%3Bto%20determine%20what%20application%20is%20using%20the%20port%3A%3C%2FP%3E%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId--140855494%22%20id%3D%22toc-hId--25363535%22%3EAdditional%20diagnostics%20-%20query%20sys.dm_hadr_availability_replica_states%20on%20the%20secondary%3C%2FH3%3E%3CBR%20%2F%3E%3CP%3EIf%20the%20above%20settings%20check%20out%2C%26nbsp%3Bquery%20the%20sys.dm_hadr_availability_replica_states%20for%20the%20last_connect_error_number%20which%20may%20help%20you%20diagnose%20the%20join%20issue.%20Depending%20on%20which%20replica%20was%20having%20difficulty%20communicating%2C%20you%20should%20query%20both%20the%20primary%20and%20secondary%20for%20the%20local%20replica%3A%3C%2FP%3E%3CBR%20%2F%3E%3CP%3Eselect%20r.replica_server_name%2C%20r.endpoint_url%2C%20%3CBR%20%2F%3E%20rs.connected_state_desc%2C%20rs.last_connect_error_description%2C%20%3CBR%20%2F%3E%20rs.last_connect_error_number%2C%20rs.last_connect_error_timestamp%20%3CBR%20%2F%3E%20from%20sys.dm_hadr_availability_replica_states%20rs%20join%20sys.availability_replicas%20r%20%3CBR%20%2F%3E%20on%20rs.replica_id%3Dr.replica_id%20%3CBR%20%2F%3E%20where%20rs.is_local%3D1%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EFor%20example%2C%20if%20the%20secondary%20was%20unable%20to%20communicate%20with%20the%20DNS%20server%20or%20if%20a%20replica's%20endpoint_url%20was%20configured%20incorrectly%20when%20creating%20the%20availability%20group%2C%20you%20may%20get%20the%20following%20results%3A%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F67844i9BC1E1382C553692%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%3CBR%20%2F%3E%3CP%3E%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-317987%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Dec%2009%2C%202013%20You%20can%20create%20an%20availability%20group%20using%20the%20New%20Availability%20Group%20wizard%20or%20using%20a%20series%20of%20transact-sql%20commands.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-317987%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EHigh%20Availability%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Jan 15 2019 03:27 PM
Updated by: