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 t开发者_StackOverflow中文版o 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
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).
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.
精彩评论