There are at least two ways you can handle long running queries
through ODBC.
- 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.
- 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.