INF: Handling Timeouts Correctly in DB-LibraryID: Q48712
|
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:
#define INCL_BASE
#define DBMSOS2
#include <os2.h>
#include <stdio.h>
#include <sqlfront.h>
#include <sqldb.h>
DBPROCESS *dbproc;
int msg_handler();
int err_handler();
static int timeout=FALSE;
main()
{
LOGINREC *login;
login = dblogin();
DBSETLUSER(login,"sa");
dbproc = dbopen(login, "server");
dbmsghandle(msg_handler);
dberrhandle(err_handler);
dbsettime(5);
dbcmd(dbproc,"select command from sqlhelp");
dbsqlexec(dbproc);
timeout_processing();
while( dbresults(dbproc) != NO_MORE_RESULTS )
{
while( dbnextrow(dbproc) != NO_MORE_ROWS )
{
.
.
.
}
}
}
int msg_handler(dbproc, msgno, msgstate, severity, msgtext)
DBPROCESS *dbproc;
DBINT msgno;
int msgstate;
int severity;
char *msgtext;
{
printf("SQL Server Message %ld, state %d, severity %d:\n%s\n",
msgno, msgstate, severity, msgtext );
return(DBNOSAVE);
}
int err_handler(dbproc, severity, dberr, oserr, dberrstr,
oserrstr)
DBPROCESS *dbproc;
int severity;
int dberr;
int oserr;
char *dberrstr;
char *oserrstr;
{
if( dberr==SQLETIME ) <--- test for timeout condition
timeout=TRUE;
else
{ printf("DB-LIB Error %d,\n%s\n",dberr,dberrstr);
if( oserr>0 )
printf("OS Error %d,\n%s\n",oserr,oserrstr);
}
return(INT_CANCEL);
}
Additional query words: dblib Windows NT
Keywords : kbprg SSrvDB_Lib SSrvProg SSrvWinNT
Version : winnt:4.2x,6.0,6.5,7.0
Platform : winnt
Issue type : kbinfo
Last Reviewed: May 4, 1999