Availability Groups (AG) and Linked servers can get really tricky. Especially if you are dealing with multi-subnet failover. The only way we have figured out how to do this is with ODBC. Here is how.
First, we have create an ODBC connection on our SQL Server. The single server in the picture below is the server we are going create the ODBC connection and the linked server on. It will go over to the AG Listener.
First we are creating an ODBC Connection on our server that is going to link to the AG.
Make sure to be in the System DSN section. Click Add
We can pick either ODBC Driver 11 or 13. This is a separate driver install that we can get here. We want to install the driver and then we will see it as an option in the screen above. Click Finish.
Give it whatever name and description wanted, but save the name for later. The server should be the name of the AG Listener. Click Next.
Technically we don’t have to put in a login and password, but I like to test the login and password that I am going to use for the linked server. It won’t be saved here. Click Next.
Here is the magic part, make sure to check multi-subnet failover. That is what is going to make the connection automatically fail between the two nodes. Click next, test the connection and then Finish. The ODBC connection is ready to be used by the linked server connection. Let’s build that part now.
Go into SQL Server Management Studio and under Server Objects, right click on Linked Servers and select “New Linked Server”.
The provider needs to be OLE DB Provider for ODBC Drivers. Remember the name we gave the ODBC connection? We are going to use that here. Then go to the Security Tab.
This is where we put in the login and it will be stored here. I also make sure this user name and password is on both Nodes of the AG with the permissions that I need. Click Server Options
The above is what I need, but I check that I am only giving access to what is needed and not more. When we click ok, it will test our connection. If everything works with no errors, we are ready to go.
Some of the problems that we have noticed are querying tables that have big datatypes like time(3-7), timestamp, and a few others. Casting or converting the datatypes doesn’t help. If we pull the table into a view without the big datatype columns, we are able to query the view from another server, but never the base table. It has been a bit frustrating, but we are still hopeful that we can find a solution or that Microsoft with fix ODBC connections. If there is a better way to do this, please reach out to me. We have things we need to solve and could use some help.
The song for this post is Mayday by Cam.
Coming soon: Count down to PASS Summit 2016 with more pictures from PASS Summit 2015. Watch twitter and the Magic Mirrors page for more.