SQL Server Replication and AlwaysOn Availability Groups

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.



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Trust DCAC with your data

Your data systems may be treading water today, but are they prepared for the next phase of your business growth?