INF: Handling Timeouts Correctly in DB-Library (48712)
The information in this article applies to:
- Microsoft SQL Server 4.2x
- Microsoft SQL Server 6.0
- Microsoft SQL Server 6.5
- Microsoft SQL Server 7.0
This article was previously published under Q48712 SUMMARY
In SQL Server, an application attempting to access data that is locked
by another user will be blocked until the lock is released. If this
causes a deadlock (both requesting locks that the other holds), SQL
Server will immediately terminate one of the participants (no timeout
is involved).
If there is no deadlock, the application requesting the locked data
will be blocked until the other user chooses to release the lock.
There is no mandatory timeout period, and there is no way to test
whether or not a data item is locked, except to attempt to access
the data (and potentially get blocked indefinitely).
With DB-Library (DB-Lib), it is possible to continue issuing commands
after a timeout has occurred. To regain control after a timeout period,
do the following:
- Use dbtimeout() to set a nonzero timeout value.
- Within the error handler, test for dberr of SQLETIME to determine
if a timeout has occurred.
- If a timeout has occurred, your error handler has the option of
either returning control to DB-LIB for another timeout interval
(DB_CONTINUE) or canceling the current command (DB_CANCEL).
- If DB_CANCEL is used, an attention will be sent to the server and
control will be returned to the statement following the dbsqlok(),
dbresults(), or dbnextrow() that was waiting.
- Do NOT call dbcancel(dbproc) from within the error handler if a
timeout has occurred. This is true even if the error handler
address has been set to null to prevent recursive calls to the
error handler. Instead, have your error handler return INT_CANCEL.
When the error handler returns INT_CANCEL after a timeout, DB-Lib
will send a cancel request to SQL Server and will continue reading
data.
Modification Type: | Major | Last Reviewed: | 12/3/2003 |
---|
Keywords: | kbinfo kbProgramming KB48712 |
---|
|