示例#1
0
 /// <summary>
 /// Determines throttling conditions from the specified SQL exception.
 ///
 /// </summary>
 /// <param name="ex">The <see cref="T:System.Data.SqlClient.SqlException"/> object that contains information relevant to an error returned by SQL Server when throttling conditions were encountered.</param>
 /// <returns>
 /// An instance of the object that holds the decoded reason codes returned from SQL Database when throttling conditions were encountered.
 /// </returns>
 public static ThrottlingCondition FromException(SqlException ex)
 {
     if (ex != null)
     {
         foreach (SqlError error in ex.Errors)
         {
             if (error.Number == 40501)
             {
                 return(ThrottlingCondition.FromError(error));
             }
         }
     }
     return(ThrottlingCondition.Unknown);
 }
示例#2
0
        public bool IsTransient(Exception ex)
        {
            if (ex != null)
            {
                SqlException sqlException;
                if ((sqlException = ex as SqlException) != null)
                {
                    foreach (SqlError error in sqlException.Errors)
                    {
                        switch (error.Number)
                        {
                        case 40501:
                            ThrottlingCondition throttlingCondition = ThrottlingCondition.FromError(error);
                            sqlException.Data[(object)throttlingCondition.ThrottlingMode.GetType().Name] = (object)throttlingCondition.ThrottlingMode.ToString();
                            sqlException.Data[(object)throttlingCondition.GetType().Name] = (object)throttlingCondition;
                            return(true);

                        case 40540:
                        case 40613:
                        case 10928:
                        case 10929:
                        case 40143:
                        case 40197:
                        case 233:
                        case 10053:
                        case 10054:
                        case 10060:
                        case 20:
                        case 64:
                            return(true);

                        default:
                            continue;
                        }
                    }
                }
                else
                {
                    return(ex is TimeoutException);
                }
            }
            return(false);
        }