How to implement SQL Azure Transient Fault Handling Framework for Dapper?

I am a vb.net guy and it is hard for me to read C #. I compiled C # Dapper in a DLL and used it in my application. My main problem is that I need to change the source code for the default integration of the Transaction Fault Handling Framework for SQL Azure in every SQL query.

I can add retry logic at the connection level because it is on top of the dapper top, but not at the runtime level that is built into the drapper class.

Has anyone else done this?

* UPDATE *

Does only ReliableSqlConnection use on top of the call does Dapper handle retry logic when executing a query without a query?

Here is a sample retry code from MS with transietn fault

using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling; using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.AzureStorage; using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.SqlAzure; using System.Data; ... using (ReliableSqlConnection conn = new ReliableSqlConnection(connString, retryPolicy)) { conn.Open(); IDbCommand selectCommand = conn.CreateCommand(); selectCommand.CommandText = "UPDATE Application SET [DateUpdated] = getdate()"; // Execute the above query using a retry-aware ExecuteCommand method which // will automatically retry if the query has failed (or connection was // dropped). int recordsAffected = conn.ExecuteCommand(selectCommand, retryPolicy); } 

Here is the Dapper code execution part, the same name is used, but I think this is a custom execution function

  private static int ExecuteCommand(IDbConnection cnn, IDbTransaction transaction, string sql, Action<IDbCommand, object> paramReader, object obj, int? commandTimeout, CommandType? commandType) { IDbCommand cmd = null; bool wasClosed = cnn.State == ConnectionState.Closed; try { cmd = SetupCommand(cnn, transaction, sql, paramReader, obj, commandTimeout, commandType); if (wasClosed) cnn.Open(); return cmd.ExecuteNonQuery(); } finally { if (wasClosed) cnn.Close(); if (cmd != null) cmd.Dispose(); } } 
+6
source share
1 answer

I would recommend wrapping a retry around Dapper, preferably using the RetryPolicy.ExecuteAction method. Thus, both the OPEN call to the connection and the command itself will be repeated using the TFH re-check policy:

For instance:

  SqlRetryPolicy.ExecuteAction(() => { // Place Dapper ExecuteCommand here: eg ExecuteCommand(conn, trans, ... ) }); 
+2
source

All Articles