示例#1
0
        /// <summary>
        /// Determines the throttling conditions from the specified reason code.
        ///
        /// </summary>
        /// <param name="reasonCode">The reason code returned by SQL Database that contains the throttling mode and the exceeded resource types.</param>
        /// <returns>
        /// An instance of the object holding the decoded reason codes returned from SQL Database when encountering throttling conditions.
        /// </returns>
        public static ThrottlingCondition FromReasonCode(int reasonCode)
        {
            if (reasonCode <= 0)
            {
                return(ThrottlingCondition.Unknown);
            }
            ThrottlingMode      throttlingMode      = (ThrottlingMode)(reasonCode & 3);
            ThrottlingCondition throttlingCondition = new ThrottlingCondition()
            {
                ThrottlingMode = throttlingMode
            };
            int num1 = reasonCode >> 8;

            throttlingCondition.throttledResources.Add(
                Tuple.Create <ThrottledResourceType, ThrottlingType>(ThrottledResourceType.PhysicalDatabaseSpace,
                                                                     (ThrottlingType)(num1 & 3)));
            int num2;

            throttlingCondition.throttledResources.Add(
                Tuple.Create <ThrottledResourceType, ThrottlingType>(ThrottledResourceType.PhysicalLogSpace,
                                                                     (ThrottlingType)((num2 = num1 >> 2) & 3)));
            int num3;

            throttlingCondition.throttledResources.Add(
                Tuple.Create <ThrottledResourceType, ThrottlingType>(ThrottledResourceType.LogWriteIoDelay,
                                                                     (ThrottlingType)((num3 = num2 >> 2) & 3)));
            int num4;

            throttlingCondition.throttledResources.Add(
                Tuple.Create <ThrottledResourceType, ThrottlingType>(ThrottledResourceType.DataReadIoDelay,
                                                                     (ThrottlingType)((num4 = num3 >> 2) & 3)));
            int num5;

            throttlingCondition.throttledResources.Add(
                Tuple.Create <ThrottledResourceType, ThrottlingType>(ThrottledResourceType.Cpu,
                                                                     (ThrottlingType)((num5 = num4 >> 2) & 3)));
            int num6;

            throttlingCondition.throttledResources.Add(
                Tuple.Create <ThrottledResourceType, ThrottlingType>(ThrottledResourceType.DatabaseSize,
                                                                     (ThrottlingType)((num6 = num5 >> 2) & 3)));
            int num7;

            throttlingCondition.throttledResources.Add(
                Tuple.Create <ThrottledResourceType, ThrottlingType>(ThrottledResourceType.Internal,
                                                                     (ThrottlingType)((num7 = num6 >> 2) & 3)));
            int num8;

            throttlingCondition.throttledResources.Add(
                Tuple.Create <ThrottledResourceType, ThrottlingType>(ThrottledResourceType.WorkerThreads,
                                                                     (ThrottlingType)((num8 = num7 >> 2) & 3)));
            throttlingCondition.throttledResources.Add(
                Tuple.Create <ThrottledResourceType, ThrottlingType>(ThrottledResourceType.Internal,
                                                                     (ThrottlingType)(num8 >> 2 & 3)));
            return(throttlingCondition);
        }
示例#2
0
 /// <summary>
 /// Determines the throttling conditions from the specified SQL error.
 ///
 /// </summary>
 /// <param name="error">The <see cref="T:System.Data.SqlClient.SqlError"/> object that contains information relevant to a warning or error returned by SQL Server.</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 FromError(SqlError error)
 {
     if (error != null)
     {
         Match match = ThrottlingCondition.sqlErrorCodeRegEx.Match(error.Message);
         int   result;
         if (match.Success && int.TryParse(match.Groups[1].Value, out result))
         {
             return(ThrottlingCondition.FromReasonCode(result));
         }
     }
     return(ThrottlingCondition.Unknown);
 }
示例#3
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);
 }
示例#4
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);
        }