Connect to an Always on Availability group listener

Modified on Mon, 14 Mar 2022 at 01:40 PM

TABLE OF CONTENTS

Introduction

The Always on availability group feature is a high availability and disaster recovery solution that provides an enterprise-level alternative to database mirroring. It maximizes the availability of a set of user databases for an organisation. 

As an example, you have 2 databases ‘SQLDBServerA’ & ‘SQLDBServerB’ and a Listener called SQLListener.

 Your connection string with the AppSettion.json file would have a "server attribute" of:

 

  • server=tcp: SQLListener; or if using a nonstandard port
  • server=tcp: SQLListener,1435; The "tcp: " (note the space) is required to force the use of TCP and needs to be added. 
  •  multiSubnetFailover=True;

 

Set up Database Connection

  • Determine the SQL listener by logging onto the SQL database server.
  • Expand the AlwaysOn High Availability folder.
  • Expand the Availability Group.
  • The SQL listener should be visible.
  • Right click on the SQL listener and select properties to determine the port number specified.

Graphical user interface, text, application

Description automatically generated

 

Graphical user interface, text, application

Description automatically generated


























  • Open up AppSetting.json file and amend accordingly.
"DatabaseConnection": "Server=tcp: SQLListener, 1433;multiSubnetFailover=True;Database=ManagementStudio;ConnectRetryCount=0;",


Graphical user interface, text, application, email

Description automatically generated



More information

How to connect to a "High Availability Listener" setup

https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/listeners-client-connectivity-application-failover?view=sql-server-ver15

 

How to connect to a "Database Mirroring" setup

https://docs.microsoft.com/en-us/sql/database-engine/database-mirroring/connect-clients-to-a-database-mirroring-session-sql-server?view=sql-server-ver15

 

SQL Connection string Syntax. (general knowledge, good to have)

https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlconnection.connectionstring?view=dotnet-plat-ext-6.0


Further Support

If you require further support, please visit ManagementStudio's Service Desk to search the knowledge base or create a new support ticket.