title: ADO/SQL Server: What is the error code for "timeout expired"?
body: <p>i'm trying to trap a &quot;timeout expired&quot; error from ADO.</p>
  <p>When a timeout happens, ADO returns:</p>
  <pre><code>Number:      0x80040E31 (DB_E_ABORTLIMITREACHED in oledberr.h)
  SQLState:    HYT00
  NativeError: 0
  </code></pre>
  <p>The <code>NativeError</code> 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.</p>
  <hr />
  <p>The <code>Number</code> (i.e. the COM hresult) looks useful, but the <a href="https://web.archive.org/web/20110921082938/http://blogs.msdn.com:80/b/joshpoley/archive/2008/01/04/errors-004-facility-itf.aspx" rel="nofollow noreferrer">definition of <code>DB_E_ABORTLIMITREACHED</code></a> in <a href="http://examples.oreilly.com/9780735619616/cd_contents/devtools/include/oledberr.h" rel="nofollow noreferrer"><code>oledberr.h</code></a> says:</p>
  <blockquote>
  <p>Execution stopped because a resource limit was reached. No results were returned.</p>
  </blockquote>
  <p>This error could apply to things besides &quot;<em>timeout expired</em>&quot; (some potentially server-side), such as a governor that limits:</p>
  <ul>
  <li>CPU usage</li>
  <li>I/O reads/writes</li>
  <li>network bandwidth</li>
  </ul>
  <p>and stops a query.</p>
  <hr />
  <p>The final useful piece is <code>SQLState</code>, which is a database-independent error code system. Unfortunately the only <a href="https://www.ibm.com/docs/en/products?topic=/com.ibm.db2.udb.doc/core/r0sttmsg.htm" rel="nofollow noreferrer">reference for SQLState error codes i can find</a> have no mention of <code>HYT00</code>.</p>
  <p>What to do?
  What do do?</p>
  <hr />
  <p><strong>Note:</strong> i can't trust</p>
  <pre><code>0x80040E31 (DB_E_ABORTLIMITREACHED)
  </code></pre>
  <p>to mean &quot;<em>timeout expired</em>&quot;, anymore than i could trust</p>
  <pre><code>0x80004005 (E_UNSPECIFIED_ERROR)
  </code></pre>
  <p>to mean &quot;<em>Transaction was deadlocked on lock resources with another process and has been chosen as the deadlock victim</em>&quot;.</p>
  <hr />
  <p>My pseudo-question becomes: does anyone have documentation on what the SQLState &quot;<code>HYT000</code>&quot; means?</p>
  <p>And my real question still remains: How can i specifically trap an ADO <em>timeout expired</em> exception thrown by ADO?</p>
  <p>Gotta love the questions where the developer is trying to &quot;<em>do the right thing</em>&quot;, but nobody knows <strong>how</strong> to do the right thing. Also gotta love how googling for <code>DB_E_ABORTLIMITREACHED</code> and this question is #9, with MSDN nowhere to be found.</p>
  <h2>Update 3</h2>
  <p>From the <a href="https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms718095%28v=vs.85%29" rel="nofollow noreferrer">OLEdb ICommand.Execute reference</a>:</p>
  <blockquote>
  <p>DB_E_ABORTLIMITREACHED</p>
  <p>Execution has been aborted because a resource limit has been reached. For example, a query timed out. No results have been returned.</p>
  </blockquote>
  <p>&quot;<em>For example</em>&quot;, meaning not an exhaustive list.</p>
  <hr />
  <h2>Update Three</h2>
  <p>Found it. Answer applied as answer.</p>