Reyaz
Reyaz

Reputation: 55

JDBC connection string for clustered environment

I have 2 nodes sql server 2012 installed and clustered and configured Always On feature with Synchronized option.

Clustername: Cluster1 node 1 name: db1 node 2 name: db2 SQL Availability group name: AVG1 has 2 IP address( 10.X.30.7 and 10.X.31.7)

N0w i need to connect to the database from the application( using tomcat 7). Could you please let me know the jdbc syntax how to connect to the database ?

What would be the SQL server name i have to mention in my application? And Could you please share JDBC connection example string with the above data?

Let me know for more details

Upvotes: 1

Views: 5871

Answers (1)

steoleary
steoleary

Reputation: 9278

So, if you have created an availability group listener, then that is the server name that you have to reference as this is the name that the windows cluster keeps online as a resource so that the servername never changes no matter what replica the availability group is running on.

The connection string also depends on what port you set the listener up on too, but I'm going to assume that you are using a default instance, your listener is called AG-Listener and it is running on port 1433:

jdbc:sqlserver://AG-Listener:1433;databaseName=YourDB;user=MyUserName;password=*****;

You can find many more examples of JDBC connection strings here:

Building the Connection URL

Upvotes: 1

Related Questions