FIX: SQLNumResultCols Results in Attentions Being Generated on SQL ServerID: Q219957
|
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.
A supported fix that corrects this problem is now available from Microsoft, but
it has not been fully regression tested and should be applied only to systems
experiencing this specific problem. If you are not severely affected by this
specific problem, Microsoft recommends that you wait for the next sqlsrv32.dll
that contains this fix.
To resolve this problem immediately, contact Microsoft Product Support Services
to obtain the fix. For a complete list of Microsoft Product Support Services
phone numbers and information on support costs, please go to the following
address on the World Wide Web:
http://www.microsoft.com/support/supportnet/overview/overview.asp
This bug was corrected in SQLSrv32.dll version 3.60.0319 and 3.70.0623.
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.
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
#include <odbcinst.h>
#include <winver.h>
#include <string.h>
#include <stdio.h>
char szConnect[] = "DSN=PUBS;UID=sa;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;
}
Additional query words:
Keywords : odbcSQL
Version : WINDOWS:3.6,3.7
Platform : WINDOWS
Issue type : kbbug
Last Reviewed: July 2, 1999