Microsoft KB Archive/219957

= FIX: SQLNumResultCols Results in Attentions Being Generated on SQL Server =

Article ID: 219957

Article Last Modified on 10/5/2005

-

APPLIES TO


 * Microsoft ODBC Driver for Microsoft SQL Server 3.6
 * Microsoft ODBC Driver for Microsoft SQL Server 3.7

-



This article was previously published under Q219957



sqlsrv32.dll versions 3.70.0623, 3.60.0319



SYMPTOMS
When Conditions are Async enabled and TCP/IP Sockets and SQLNumResultCols are issued after a SQLPrepare but prior to a SQLExecute, the driver issues SET FMTONLY ON to get the column information, which then ends up breaking the connection and results in the generation of the Attention.



RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that is described in this article. Only apply it to systems that are experiencing this specific problem. This hotfix may receive additional testing. Therefore, if you are not severely affected by this problem, we recommend that you wait for the next sqlsrv32.dll that contains this hotfix.

To resolve this problem immediately, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

Workaround
As a work around you can use either of the following:


 * Disable ASYNC.

-or-
 * Move the SQLNumResultCols call after the SQLExecute.



STATUS
This bug was corrected in SQLSrv32.dll version 3.60.0319 and 3.70.0623.



MORE INFORMATION
The following code should demonstrate the problem. Set your data source name (DSN) to Pubs up to use sockets then run. Watch a SQLTrace window and you should see the Attention's being generated and the application should hang when trying to execute the SQLNumResultCols command. An ODBC trace shows a steady string of SQL_STILL_EXECUTING returns. Switching the SQLNumResultCols command to occur after the Execute resolves the problem.

Note You must change uid= and pwd= to the correct values before you run this code. Make sure that uid has the appropriate permissions to perform this operation on the database.
 * 1) include 
 * 2) include 
 * 3) include 
 * 4) include 
 * 5) include 
 * 6) include 
 * 7) include 

char szConnect[] = "DSN=PUBS;UID= ;PWD= ";

char szQuery[] = "SELECT au_id FROM Authors";

main {   HENV henv; HDBC hdbc; HSTMT hstmt; RETCODE rtcd; short wcbOut; short cyclecnt = 0;

char szBuf[2001]; WORD cbBufMax = 2000; char *  pszBuf = szBuf; SQLSMALLINT parmcnt; SQLSMALLINT * parmcntptr = &parmcnt;

rtcd = SQLAllocEnv(&henv); rtcd = SQLAllocConnect(henv, &hdbc);

rtcd = SQLDriverConnect(hdbc, NULL,(unsigned char *) szConnect,               strlen(szConnect), NULL, 0, &wcbOut,                SQL_DRIVER_NOPROMPT); //Needs to be in async rtcd = SQLSetConnectOption(hdbc,SQL_ASYNC_ENABLE,SQL_ASYNC_ENABLE_ON); rtcd = SQLAllocStmt(hdbc, &hstmt); do   { rtcd = SQLPrepare(hstmt, (unsigned char *)szQuery, strlen(szQuery)); //If the SQLNumResultCols is moved to after the execute this will work fine. do       { rtcd = SQLNumResultCols(hstmt, parmcntptr); }  while (rtcd == SQL_STILL_EXECUTING); do        { rtcd = SQLExecute(hstmt); //rtcd = SQLExecDirect(hstmt,(unsigned char *) szQuery, strlen(szQuery));

} while (rtcd == SQL_STILL_EXECUTING); //use SQLNumResultCols here and it works fine /*     do        { rtcd = SQLNumResultCols(hstmt, parmcntptr); }  while (rtcd == SQL_STILL_EXECUTING); rtcd = SQLFreeStmt(hstmt, SQL_CLOSE); cyclecnt++; }  while (cyclecnt < 20);

return 0; }

Keywords: kbbug kbfix kbodbc360fix kbmdacnosweep KB219957

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.