public static IDataReader ExecuteReaderWithRetry(this IDbCommand command, CommandBehavior behavior, RetryPolicy commandRetryPolicy, RetryPolicy connectionRetryPolicy, string operationName = "ExecuteReader")
        {
            GuardConnectionIsNotNull(command);
            var effectiveCommandRetryPolicy = (commandRetryPolicy ?? RetryPolicy.NoRetry).LoggingRetries(operationName);

            return(effectiveCommandRetryPolicy.ExecuteAction(() =>
            {
                var weOwnTheConnectionLifetime = EnsureValidConnection(command, connectionRetryPolicy);
                try
                {
                    return command.ExecuteReader(behavior);
                }
                catch (Exception)
                {
                    if (weOwnTheConnectionLifetime && command.Connection != null && command.Connection.State == ConnectionState.Open)
                    {
                        command.Connection.Close();
                    }
                    throw;
                }
            }));
        }
 public static IDataReader ExecuteReaderWithRetry(this IDbCommand command, CommandBehavior behavior, RetryPolicy retryPolicy, string operationName = "ExecuteReader")
 {
     return(command.ExecuteReaderWithRetry(behavior, retryPolicy, RetryPolicy.NoRetry));
 }
 public static int ExecuteNonQueryWithRetry(this IDbCommand command, RetryPolicy retryPolicy, string operationName = "ExecuteNonQuery")
 {
     return(command.ExecuteNonQueryWithRetry(retryPolicy, RetryPolicy.NoRetry, operationName));
 }
        public static int ExecuteNonQueryWithRetry(this IDbCommand command, RetryPolicy commandRetryPolicy, RetryPolicy connectionRetryPolicy, string operationName = "ExecuteNonQuery")
        {
            GuardConnectionIsNotNull(command);
            var effectiveCommandRetryPolicy = (commandRetryPolicy ?? RetryPolicy.NoRetry).LoggingRetries(operationName);

            return(effectiveCommandRetryPolicy.ExecuteAction(() =>
            {
                var weOwnTheConnectionLifetime = EnsureValidConnection(command, connectionRetryPolicy);
                try
                {
                    return command.ExecuteNonQuery();
                }
                finally
                {
                    if (weOwnTheConnectionLifetime && command.Connection != null && command.Connection.State == ConnectionState.Open)
                    {
                        command.Connection.Close();
                    }
                }
            }));
        }
 public static object ExecuteScalarWithRetry(this IDbCommand command, RetryPolicy retryPolicy, string operationName = "ExecuteScalar")
 {
     return(ExecuteScalarWithRetry(command, retryPolicy, RetryPolicy.NoRetry));
 }