Ev.
Ev.

Reputation: 7579

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

Upvotes: 3

Views: 1435

Answers (2)

maddom
maddom

Reputation: 106

It looks like it may be a connection timeout, rather than a command timeout.

I would check to make sure that you can connect and run the query with a more sensible timeout value just to verify this.

Upvotes: 0

Jeff Sternal
Jeff Sternal

Reputation: 48675

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).

Upvotes: 6

Related Questions