public bool IsTransient(Exception ex) { Tracer.TraceEvent(TraceEventType.Verbose, 0, "AzureSqlStrategy is starting"); var msStrategy = new SqlDatabaseTransientErrorDetectionStrategy(); var isTransient = msStrategy.IsTransient(ex); if (!isTransient) { SqlException sqlException; if ((sqlException = ex as SqlException) != null) { var msg = sqlException.ToString().ToLower(); if (msg.Contains("physical connection is not usable")) { Tracer.TraceEvent(TraceEventType.Verbose, 0, "AzureSqlStrategy: physical connection is not usable"); isTransient = true; } else if (msg.Contains("timeout expired")) { Tracer.TraceEvent(TraceEventType.Verbose, 0, "AzureSqlStrategy: timeout expired"); isTransient = true; } } } Tracer.TraceEvent(TraceEventType.Verbose, 0, "AzureSqlStrategy: is transient: {0}", isTransient); return isTransient; }
/// <summary> /// Determines whether the specified exception represents a transient failure that can be compensated by a retry. /// </summary> /// <param name="ex">The exception object to be verified.</param> /// <returns>True if the specified exception is considered as transient, otherwise false.</returns> public bool IsTransient(Exception ex) { // using the standard transient detection logic first var defaultDetectionStrategy = new SqlDatabaseTransientErrorDetectionStrategy(); if (defaultDetectionStrategy.IsTransient(ex)) return true; var sqlException = ex as SqlException; if (sqlException == null) return false; foreach (SqlError err in sqlException.Errors) { switch (err.Number) { // sql connection timeout case -2: return true; // transaction deadlock case 1205: return true; // worker thread concurrency limit case 10928: return true; // system is too busy case 10929: return true; default: return false; } } return false; }