I've been seeing intermittent SqlException - "Timeout expired" in our application quite regularly. We have implemented transient retry logic as per
http://social.technet.microsoft.com/wiki/contents/articles/sql-azure-connection-management-in-sql-azure.aspx
and
http://msdn.microsoft.com/en-us/library/4cff491e-9359-4454-bd7c-fb72c4c452ca
but neither of those documents mentioned the -2 timeout error and as a result we don't retry. But the regularity with which we see these exceptions seems to tell me that I'm doing something wrong and perhaps I should retry.
Additionally, the first document above infers that the second is the definitive resource, yet the second doc does not mention error code 40143 (which we also had not implemented as a retry-able error but appears that we should).
I'd really like to get the definitive list (so that my app would stop sending me SMS alerts in the middle of the night!)
For the record (and to pass on some code) , my app is testing as follows:
public static class SqlExceptionExtensions { public static bool IsRetryable( this SqlException that ) { //for error descriptions go to: //http://social.technet.microsoft.com/wiki/contents/articles/sql-azure-connection-management-in-sql-azure.aspx //http://msdn.microsoft.com/en-us/library/4cff491e-9359-4454-bd7c-fb72c4c452ca var sqlErrorCodesToRetry = new[] { -2 /*Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.*/ , 20 /*The instance of SQL Server you attempted to connect to does not support encryption. (PMcE: amazingly, this is transient)*/ , 64 /*A connection was successfully established with the server, but then an error occurred during the login process.*/ , 233 /*The client was unable to establish a connection because of an error during connection initialization process before login*/ , 10053 /*A transport-level error has occurred when receiving results from the server.*/ , 10054 /*A transport-level error has occurred when sending the request to the server.*/ , 10060 /*A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible.*/ , 40143 /*The service has encountered an error processing your request. Please try again.*/ , 40197 /*The service has encountered an error processing your request. Please try again.*/ , 40501 /*The service is currently busy. Retry the request after 10 seconds.*/ , 40613 /*Database '%.*ls' on server '%.*ls' is not currently available. Please retry the connection later.*/ }; return that.Errors.Cast<SqlError>().Any( sqlError => sqlErrorCodesToRetry.Contains( sqlError.Number ) ); } }