INF: Result Processing for SQL ServerID: Q165951
|
When using Microsoft DB-Library, VBSQL (VBX and OCX), or ODBC to access SQL
Server, it is critical that all result sets are completely processed in a
timely manner. The result sets need to be processed to avoid problems with
subsequent SQL Server queries and to avoid concurrency issues with SQL
Server resources.
In most cases the return code from dbsqlok or dbsqlexec should be ignored.
If you send the following batch:
insert into tblTest values(1)
select @@VERSION
The following are the most common problems your application may encounter
if result sets are not handled immediately and completely:
DB-Library prevents you from sending additional queries if there are results from a previous query that need to be handled. For more information, see the following article in the Microsoft Knowledge Base:10038 - Attempt to initiate a new SQL Server operation with results pending.
Q117143 : When and How to Use dbcancel() or sqlcancel()
Q162361 : Understanding and Resolving SQL Server Blocking Problems
BOOL bMoreResults = TRUE;
BOOL bMoreRows = TRUE;
RETCODE dbRC = SUCCEED;
//
// send query
.
.
.
//
// process *all* results
bMoreResults = TRUE
while(bMoreResults)
{
switch(dbRC = dbresults(pdbproc))
{
case SUCCEED:
bMoreRows = TRUE;
while(bMoreRows)
{
switch(dbRC = dbnextrow(pdbproc))
{
case REG_ROW:
// handle regular row
break;
case NO_MORE_ROWS:
bMoreRows = FALSE; // all rows in this result set handled
break;
case BUF_FULL:
// handle full buffer when using row buffering
break;
case FAIL:
// any error processing desired
bMoreRows = FALSE;
break;
default:
// handle compute row
break;
}
}
break;
case NO_MORE_RESULTS:
bMoreResults = FALSE; // all result sets handled
break;
case FAIL:
// any error processing desired
// The current command has returned an error
// could be a non fatal error
bMoreResults = TRUE;
break;
case NO_MORE_RPC_RESULTS:
// extract stored procedure return information
break;
default:
bMoreResults = FALSE; // unknown
break;
}
} // while(bMoreResults && FALSE == DBDEAD(pdbproc))
Keywords : kbprg kbusage SSrvProg
Version : 4.21a 6.0 6.5
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 9, 1999