| INF: Result Processing for SQL ServerLast reviewed: September 15, 1997Article ID: Q165951 | 
| The information in this article applies to: 
 
 SUMMARYWhen 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 @@VERSIONand the insert statement fails due to a duplicate key, a Sev 14 error is generated but the batch continues. THe dbsqlok and dbsqlexec calls only check the success of the first command. If you do not call dbresults you will not process the select statement results and can get result pending errors. 
 
 MORE INFORMATIONThe following are the most common problems your application may encounter if result sets are not handled immediately and completely: 
 
    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 : SSrvProg kbprg kbusage Version : 4.21a 6.0 6.5 Platform : WINDOWS Issue type : kbhowto Solution Type : Info_Provided | 
| ================================================================================ 
 © 1998 Microsoft Corporation. All rights reserved. Terms of Use. |