1

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**
}
4

3 に答える 3

1

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

于 2012-09-06T21:31:42.173 に答える
1

Looks like that's the inner exception, not the actual exception you caught. What is the type of the outer exception? The only thing you can do is catch whichever type the caught exception is, and then inspect the inner exception:

try
{
    // Stuff
}
catch (Exception exc)
{
    if (exc.InnerException is System.Data.SqlClient.SqlException)
    {
        var sqlException = exc.InnerException as System.Data.SqlClient.SqlException;

        // Do stuff with the error.
    }
}

The moral of the story is you can't explicitly catch the inner exception :(

于 2012-09-06T21:38:20.603 に答える
1

Try Microsoft.Data.SqlClient.SqlException instead of System.Data.SqlClient.SqlException

        catch (Microsoft.Data.SqlClient.SqlException ex)
        {

        }
于 2020-07-10T14:46:19.660 に答える