Search code examples
c#entity-frameworkentity-framework-4azure-sql-databasesqlclient

SqlClient SqlException not caught


I have a Azure worker role perform simple selects on a SQL Azure database. Rarely it throws the following SqlException.

Log

The underlying provider failed on Open. Inner Exception: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. Exception Type: System.Data.SqlClient.SqlException

The exception is not caught as a SqlException. It is caught in the generic exception handler. Any suggestions as to why that would be?

try{
}
catch(System.Data.SqlClient.SqlException sqlExcep)
{
}
catch(Exception genericExcep)
{
    **//The exception is caught as a generic exception**
}

Solution

  • The SQL Database environment is a layer of routers and proxies that handle network load balancing and resource management. If SQL Database itself didn't timeout, then something else in the middle could have (although that's typically rare).

    I usually handle IOException errors as well and treat some of them as a form of transient error. What exception type are you actually receiving?

    Did you try implementing the Transient Fault Handling Application Block? http://msdn.microsoft.com/en-us/library/hh680934(v=pandp.50)

    Herve