private void HandleWithRetry(string sql, Action<string> action, int attempt)
{
try
{
action.Invoke(sql);
}
catch (Exception exception)
{
if (attempt < 6 && _errorChecker.IsTransient(exception))
{
Thread.Sleep(5);
HandleWithRetry(sql, action, ++attempt);
}
var message = exception.Message;
SqlException sqlException;
if ((sqlException = exception as SqlException) != null)
{
message = message + Environment.NewLine + "Error numbers: " +
string.Join(", ", sqlException.Errors.OfType<SqlError>().Select(e => e.Number));
}
throw;
}
}
}