ADO/SQL Server: What is the error code for "timeout expired"?

Posted by Ian Boyd on Stack Overflow See other posts from Stack Overflow or by Ian Boyd
Published on 2010-06-04T21:28:07Z Indexed on 2010/06/05 17:12 UTC
Read the original article Hit count: 360

i'm trying to trap a "timeout expired" error from ADO.

When a timeout happens, ADO returns:

Number:      0x80040E31 (DB_E_ABORTLIMITREACHED in oledberr.h)
SQLState:    HYT00
NativeError: 0

The NativeError of zero makes sense, since the timeout is not a function of the database engine (i.e. SQL Server), but of ADO's internal timeout mechanism.


The Number (i.e. the COM hresult) looks useful, but the definition of DB_E_ABORTLIMITREACHED in oledberr.h says:

Execution stopped because a resource limit was reached. No results were returned.

This error could apply to things besides "timeout expired" (some potentially server-side), such as a governor that limits:

  • CPU usage
  • I/O reads/writes
  • network bandwidth

and stops a query.


The final useful piece is SQLState, which is a database-independent error code system. Unfortunately the only reference for SQLState error codes i can find have no mention of HYT00.

What to do? What do do?


Note: i can't trust

0x80040E31 (DB_E_ABORTLIMITREACHED)

to mean "timeout expired", anymore than i could trust

0x80004005 (E_UNSPECIFIED_ERROR)

to mean "Transaction was deadlocked on lock resources with another process and has been chosen as the deadlock victim".


My pseudo-question becomes: does anyone have documentation on what the SQLState "HYT000" means?

And my real question still remains: How can i specifically trap an ADO timeout expired exception thrown by ADO?

Gotta love the questions where the developer is trying to "do the right thing", but nobody knows how to do the right thing. Also gotta love how googling for DB_E_ABORTLIMITREACHED and this question is #9, with MSDN nowhere to be found.

Update 3

From the OLEdb ICommand.Execute reference:

DB_E_ABORTLIMITREACHED

Execution has been aborted because a resource limit has been reached. For example, a query timed out. No results have been returned.

"For example", meaning not an exhaustive list.

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about exception-handling