Using jTDS to connect to SQL Server 2012 availabil

2019-06-04 01:07发布

问题:

I am working on a legacy project that uses jTDS to connect to SQL server. The client wants us to support SQL Server 2012 AlwaysOn. one key requirement is the ability of our application to automatically reconnect to secondary server in event of failover.

unfortunately, jTDS 3.0 does not support AlwaysOn. I have 2 options

  1. use MS JDBC (http://www.microsoft.com/en-us/download/confirmation.aspx?id=11774)
  2. Write a wrapper that returns the connection string after checking the status of the active node

option 1 is serious engineering(heavy testing) effort. Has anyone tried option 2 or something else to use jTDS to connect to SQL 2012 avilablity group listener? if yes please provide some guidance

回答1:

After tweaking my DAL to handle specific SQL Errors, I was able to retry all the transactions whenever there was a Availability group fail-over.

I am handling the following SQL Errors

Severity 16 DB error codes (10054, 233, 232, 2812, 64, 3906) Severity 14 Db error codes (983, 922, 945)