How to tell if a timeout exception occures

  • Thread starter Thread starter Jeremy Chapman
  • Start date Start date
J

Jeremy Chapman

If a time out occures an SqlException is thrown, but how can I
programatically tell if the SqlException is a timeout error vs some other
type?
 
I suggest you check SqlException.Number. However, I don't know the
error number for connection timeout, you may need to test to see.
 
if( sqlException.Number == -2 && sqlException.Class == 10 )
for a normal timeout this is what you get
 
Thanks. Are these numbers defined somewhere in the framework, because I
can't find -2 documented there or in the sql documentation.
 
Some of these (I’ve tried to classify the most common exceptions) are in the
SQL Server documentation.
But for some is just plain debugging you got the exception look at the
message and you know now when occurs.
BTW: these are the values you going to get when using the native database
provider, for ODBC there are other conditions.
 
Back
Top