Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to ReliableSqlConnection for async Azure SQL calls

We are currently using ReliableSqlConnection for all calls to our Azure SQL database. This works fine. But unfortunately the Enterprise Library is from 2013 and it seems not to be developed anymore. But the main issue is, that async db calls are not supported.

I've been searching SO and other places, but the only thing I could find so far was Polly. And even Polly does not seem to be widely used and I have not found an example for SQL Server. I know that ADO.NET supports retry for SqlConnection.Open(), but not for commands, so it's not a real solution. I'm a bit surprised that we seem to be the only ones having this problem?

like image 656
Remy Avatar asked Oct 26 '25 10:10

Remy


1 Answers

Little known fact, transient fault tolerance is now built into the connection string (.NET 4.6.1+). This document says:

If your client program connects to to Azure SQL Database by using the .NET Framework class System.Data.SqlClient.SqlConnection, you should use .NET 4.6.1 or later (or .NET Core) so you can leverage its connection retry feature. Details of the feature are here.

When you build the connection string for your SqlConnection object, you should coordinate the values among the following parameters:

ConnectRetryCount (Default is 1. Range is 0 through 255.)
ConnectRetryInterval (Default is 1 second. Range is 1 through 60.)
Connection Timeout (Default is 15 seconds. Range is 0 through 2147483647)

Specifically, your chosen values should make the following equality true:

Connection Timeout = ConnectRetryCount * ConnectionRetryInterval

For example, if the count = 3, and interval = 10 seconds, a timeout of only 29 seconds would not quite give the system enough time for its 3rd and final retry at connecting: 29 < 3 * 10.

like image 135
evilSnobu Avatar answered Oct 28 '25 23:10

evilSnobu