SQL Server Replication and AlwaysOn Availability Groups

Published On: 2021-04-12By:

Using SQL Server Replication with AlwaysOn Availability Groups is a pretty straightforward process at this point. Having the publisher be a member of an Availability Group has been supported for years now. You can however run into trouble when trying to create a new replication publication on a server that isn’t the server that you were using as the Primary server when you set up the first publication. When using a different server in the availability group you’ll get an error back from SQL Server Management Studio which says “Could not find server {old primary server} in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers. Error 7202”.

Let me explain what is happening, and how to work around it.

sql1a – Server that was the active replica when the initial publication was setup

sql1b – server that is now the active replica

If you try to set up a new publication on sql1b, you’ll get the error message that is described above. If you write out the replication commands manually you won’t get this error. This error only happens within the GUI.

The easy solution is to fail the Availability Group back to sql1a and create the publication. But what if that isn’t an option because that server no longer exists? The easy solution here is to create a linked server on all the servers in the AG, using the name of the server that was used to set up replication initially, in this case, sql1a. I then configure this linked server to point to the Availability Group listener name. So that way the linked servers, on any server, will always point to the active server. If you are setting up replication you are on the active server already, so the linked server just points back to itself.

By setting up a linked server with this name, that points back to the listener this allows replication publications to be created which sql1b is the active replica within the Availability Group.

It’s a quick and easy fix that’ll get you past the error message that SQL Server Management Studio is throwing.


Contact the Author | Contact DCAC


Globally Recognized Expertise

As Microsoft MVP’s and Partners as well as VMware experts, we are summoned by companies all over the world to fine-tune and problem-solve the most difficult architecture, infrastructure and network challenges.

And sometimes we’re asked to share what we did, at events like Microsoft’s PASS Summit 2015.

Awards & Certifications

Microsoft Partner   Denny Cherry & Associates Consulting LLC BBB Business Review    Microsoft MVP    Microsoft Certified Master VMWare vExpert
American Business Award 2021 Gold    American Business Award 2021 Bronze    FT Americas’ Fastest Growing Companies 2021   INC 5000 Award for 2020    American Business Awards People's Choice    American Business Awards Gold Award    American Business Awards Silver Award
FT Americas’ Fastest Growing Companies 2020       Best Full-Service Cloud Technology Consulting Company       Insights Sccess Award    Technology Headlines Award
Share via
Copy link