Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly setup the connection string to availability group for legacy app

Imagine you have the following scenario:

  • A .net framework 2.0 legacy client app.
  • An SQL Server 2016 Always On Availability Group.

How the connection string should be?

I can think on two options:

  • Specify the availability group listener name as the Data Source.
  • Specify the primary replica as the Data Source and secondary replica as the Failover Partner

Which one should I use to get high availability and automatic failover? Other options?

like image 764
Jesús López Avatar asked Jan 06 '18 08:01

Jesús López


People also ask

How do I connect to availability group listener?

After creating the Availability Group, you can configure the listener from Availability Groups -> Group Name -> Add Listener. Either in the create an availability group listener or the New Availability Group Listener wizards, specify the Listener DNS Name, Port, and Network Mode values.

How do I add a connection string in Visual Studio?

In Solution Explorer, double-click the My Project icon (Visual Basic) or Properties icon (C#) to open the Project Designer. Select the Settings tab. Enter a Name for the connection string. Refer to this name when accessing the connection string in code.

How do I set up an availability group in SQL Server?

In SQL Server Configuration Manager, click SQL Server Services, right-click SQL Server (<instance name>), where <instance name> is the name of a local server instance for which you want to enable Always On Availability Groups, and click Properties. Select the Always On High Availability tab.

How many IP address needed for SQL Server Alwayson?

In SQL Listener, we have two virtual IP address mapped with a SQL Listener name. Step 1: Once the application tries to connect to the database using a SQL listener, it connects with DNS and asks for the IP address of it.


1 Answers

By the book is always to use the AG listener. I guess at the moment your connection string looks something like this:

Data Source=myServerAddress;Failover Partner=myMirrorServerAddress;
Initial Catalog=myDataBase;Integrated Security=True;

But if you successfully created an AG group, then change the connection string to use the AG listener, it would look something like this:

Server=tcp:MyAgListener,1433;Database=Db1;IntegratedSecurity=SSPI; 
MultiSubnetFailover=True  
like image 167
Knotty Avatar answered Oct 21 '22 01:10

Knotty