Handle long-running queries

There are at least two ways you can handle long running queries through ODBC.

  1. An application can set the SQL_ATTR_QUERY_TIMEOUT connection attribute to specify the maximum amount of time a query can run. Note, the query will not start if the SQL Optimizer determines that the amount of time needed to process the query will exceed the SQL_ATTR_QUERY_TIMEOUT value. The default value for SQL_ATTR_QUERY_TIMEOUT is 0 which indicates that the query will run until completion.
  2. An application can call the SQLCancel API. To do this an application needs to be multi-threaded. While the long running query is running on one thread, another thread calls SQLCancel using the same statement handle.