Trapping for Connection and Command Timeout

G

Guest

FW: 1.1

What is the best method for trapping timeout exceptions? There does not
seem to be specific exceptions thrown for connection or command timeout.
Should I check the message for "Timeout", or is there some other propery in
the exception that better identifies a connection or command timeout? Thanks
for your help.
 
W

William \(Bill\) Vaughn

Ah, I usually handle this in separate routines--one that connects, another
that queries. You can take this approach, close the "testing" connection and
use Fill that opens the connection and queries in the same atomic operation.
Yes, I expect you're going to have to do some parsing or experiment to see
what your provider returns s far as Error object properties and settings.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
_________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)


INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
T

Thomas Weingartner

Catch the Exceptions and evaluate the corresponding field:

Timeout: OleDbException.ErrorCode == -2147217871

Timeout: SqlException.Number == -2 (This is an ADO.NET error code)
General Network Error: SqlException.Number == 11
Deadlock: SqlException.Number == 1205 (This is an SQL Server error code)

We handle the "General Network Error" as a timeout exception too. It only occurs under rare circumstances e.g. when your update/insert/delete query will raise a long running trigger.


Greetings from Switzerland
Thomas
 
G

Guest

Bill/Thomas, thank you for your replies.



Thomas Weingartner said:
Catch the Exceptions and evaluate the corresponding field:

Timeout: OleDbException.ErrorCode == -2147217871

Timeout: SqlException.Number == -2 (This is an ADO.NET error code)
General Network Error: SqlException.Number == 11
Deadlock: SqlException.Number == 1205 (This is an SQL Server error code)

We handle the "General Network Error" as a timeout exception too. It only occurs under rare circumstances e.g. when your update/insert/delete query will raise a long running trigger.


Greetings from Switzerland
Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top