Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SqlException not being caught

I have an ASP.Net application with the following code:

    try
    {
        sql = new SqlProc("prcCustomerAgeSelect",
            SqlProc.InParam("@DateFrom", SqlDbType.DateTime, 8, _OrderDateFrom),
            SqlProc.InParam("@DateTo", SqlDbType.DateTime, 8, _OrderDateTo),
        sql.Command.CommandTimeout = 1;
        dt = sql.ExecuteTable();

    }
    catch (SqlException ex)
    {
        Filter.ErrorMessage = "Please narrow your search criteria.";
    }

Note the line:

sql.Command.CommandTimeout = 1;

Which causes a SqlException to be thrown (for testing).

I would have thought that the catch block would catch this exception, but it doesn't. Instead, I get:

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

[SqlException (0x80131904): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.]

Why doesn't it catch it?? Am I using the wrong type? What am I missing here?

Thanks in advance!!

-Ev

like image 474
Ev. Avatar asked Dec 02 '25 04:12

Ev.


1 Answers

It sounds like what you're seeing isn't a SqlException.

It's possible that SqlProc is itself catching SqlExceptions, extracting some information from them, then throwing new exceptions of a different type (embedding some of the original info in the new exception's message).

like image 153
Jeff Sternal Avatar answered Dec 03 '25 17:12

Jeff Sternal