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

I am trying to catch the "timeout expired" error from ADO.

When a timeout occurs, ADO returns:

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

A NativeError zero makes sense because the timeout is not a function of the database engine (i.e. SQL Server), but an internal ADO timeout mechanism.


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

Execution stopped because the resource limit has been reached. Results were not returned.

This error may apply to things other than “time out” (some potentially server-side), for example, for a controller that restricts:

  • CPU usage
  • Read / Write I / O
  • network bandwidth

and stops the request.


The final useful part is SQLState , which is a database-independent error code system. Unfortunately, only the link to the SQLState error codes that I can find does not mention HYT00 .

What to do? What to do?


Note: I can not trust

 0x80040E31 (DB_E_ABORTLIMITREACHED) 

means "timeout expired" is more than I could trust

 0x80004005 (E_UNSPECIFIED_ERROR) 

means that "The transaction was locked when resources were locked by another process and selected as a victim of a deadlock."


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

And my real question still remains: how can I specifically catch the ADO timeout exception thrown by ADO?

Gotta love the questions that the developer is trying to “do right”, but no one knows how to do the right thing. You also need to love how googling for DB_E_ABORTLIMITREACHED , and this question number 9, with MSDN is nowhere to be found.

Update 3

From the OLEdb ICommand.Execute link :

DB_E_ABORTLIMITREACHED

Execution canceled because the resource limit has been reached. For example, the request timeout. Results not returned.

For example, which means a non-exhaustive list.


Update three

Found. The answer is used as the answer.

+4
source share
2 answers

You can safely use the HYT00 to indicate " HYT00 out . " Below is a link to Microsoft SQLSTATEs . He mentions HYT00 SQLSTATE:

The following SQLSTATEs indicate errors or warnings at runtime and are good candidates on which programming logic is based. However, there is no guarantee that all drivers will return them.

01004 (data truncated)

01S02 (parameter value changed)

HY008 (operation canceled)

HYC00 (additional function not implemented)

HYT00 (Timed out waiting)

Which then refers to Appendix A: ODBC Error Codes in the ODBC Programmers Reference , which specify SQLSTATE values:

  • HYT00 out and, interestingly,
  • HYT01 out

So you can use HYT00 for "Timed out".

+2
source

Isn't that just -2 or is it too obvious?

You can create this in both SSMS and Ado.net, and we use this to decide whether to repeat.

Old SO question and link and MSDN

0
source

Source: https://habr.com/ru/post/1311915/


All Articles