When you try to set a connection attribute of an ODBC
connection where connection pooling is enabled by using ODBC Driver API with
Microsoft SQL Server ODBC Driver, you receive the following error
message:
A supported hotfix is available from Microsoft. However, this hotfix is intended to correct only the problem that is described in this article. Apply this hotfix only to systems that are experiencing this specific problem.
If the hotfix is available for download, there is a "Hotfix download available" section at the top of this Knowledge Base article. If this section does not appear, submit a request to Microsoft Customer Service and Support to obtain the hotfix.
Note If additional issues occur or if any troubleshooting is required, you might have to create a separate service request. The usual support costs will apply to additional support questions and issues that do not qualify for this specific hotfix. For a complete list of Microsoft Customer Service and Support telephone numbers or to create a separate service request, visit the following Microsoft Web site:
Note The "Hotfix download available" form displays the languages for which the hotfix is available. If you do not see your language, it is because a hotfix is not available for that language. The English
version of this fix has the file attributes (or later) that are listed in the
following table. The dates and times for these files are listed in coordinated
universal time (UTC). When you view the file information, it is converted to
local time. To find the difference between UTC and local time, use the
Time Zone tab in the Date and Time tool in Control Panel.
MDAC 2.7 SP1
Date Time Version Size File name
--------------------------------------------------------
13-Oct-2002 19:24 90,112 Dahotfix.exe
03-Jul-2003 04:09 2000.81.9031.51 372,736 Sqlsrv32.dll
MDAC 2.8
Date Time Version Size File name
--------------------------------------------------------
31-Mar-2004 16:44 2000.85.1040.0 24,576 Odbcbcp.dll
31-Mar-2004 16:43 2000.85.1040.0 401,408 Sqlsrv32.dll
Note For a list of all the hotfixes available for MDAC
2.8, click the following article number to view the article in the Microsoft
Knowledge Base:
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. This problem was corrected in Microsoft Data Access Component
2.7 Service Pack 1 Refresh and Microsoft Data Access Components 2.8.
You see the problem that is mentioned in the "Symptoms"
section of this article only when you have the Microsoft Data Access Component
(MDAC) 2.7 Service Pack 1 installed on your computer.
Steps to reproduce the behavior
Use the following code to reproduce the problem:
// ODBCTestCase.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
#include "sqlext.h"
#include "sql.h"
#include "stdlib.h"
void GetSQLError();
long InitializeEnvironment();
long Connect(BOOL lbUseDSN);
long Disconnect();
int ExecuteProcedure();
SQLHENV ghEnvironment = NULL;
SQLHDBC ghConnection = NULL;
HSTMT ghStatement = NULL;
/**********************************************
* main
**********************************************/
int main(int argc, char* argv[])
{
BOOL lbTransaction = TRUE;
BOOL lbUseDSN = FALSE;
long lValue =0;
if(argc > 1)
{
if(strcmp(argv[1], "DSN") == 0)
lbUseDSN = TRUE;
if(argc > 2)
{
if(strcmp(argv[2], "TRAN") == 0)
lbTransaction = TRUE;
}
}
if(InitializeEnvironment() == 0)
{
for(long llSub = 0; llSub < 2; llSub++)
{
if(Connect(lbUseDSN) == 0)
{
if(lbTransaction)
SQLSetConnectOption(ghConnection, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
//SQLGetConnectAttr(ghConnection,SQL_ATTR_AUTOCOMMIT,&lValue,0,NULL);
ExecuteProcedure();
if(lbTransaction)
{
SQLTransact(ghEnvironment, ghConnection, SQL_COMMIT);
//If you do not call the following, the problem does not occur:
SQLSetConnectOption(ghConnection, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_ON);
//If you call the following the problem does not occur:
//SQLSetConnectOption(ghConnection, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
//SQLGetConnectAttr(ghConnection,SQL_ATTR_AUTOCOMMIT,&lValue,0,NULL);
}
Disconnect();
}
}
SQLFreeHandle(SQL_HANDLE_ENV, ghEnvironment);
}
return 0;
}
/**********************************************
* InitializeEnvironment
**********************************************/
long InitializeEnvironment()
{
if (!SQL_SUCCEEDED(SQLSetEnvAttr(NULL,
SQL_ATTR_CONNECTION_POOLING,
(SQLPOINTER)SQL_CP_ONE_PER_DRIVER,
SQL_IS_INTEGER)))
{
GetSQLError();
return 8;
}
if(!SQL_SUCCEEDED(SQLAllocHandle(SQL_HANDLE_ENV, NULL, &ghEnvironment)))
{
GetSQLError();
return 8;
}
if(!SQL_SUCCEEDED(SQLSetEnvAttr(ghEnvironment, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC2, SQL_IS_INTEGER)))
{
GetSQLError();
return 8;
}
if (!SQL_SUCCEEDED(SQLSetEnvAttr(ghEnvironment,
SQL_ATTR_CP_MATCH,
(SQLPOINTER) SQL_CP_STRICT_MATCH ,
//(SQLPOINTER) SQL_CP_RELAXED_MATCH ,
SQL_IS_INTEGER)))
{
GetSQLError();
return 8;
}
return 0;
}
/**********************************************
* Connect
**********************************************/
long Connect(BOOL lbUseDSN)
{
SQLCHAR lszOutConnectString[1024];
SQLSMALLINT llReturnLength;
SQLAllocHandle(SQL_HANDLE_DBC, ghEnvironment, &ghConnection);
// If you set the isolation before opening the connection, no error reported.
// Customer cannot set this attribute before opening connection because the object
// is running under COM+, and under COM+ isolation levels automatically are set to serializable
// if(!SQL_SUCCEEDED(::SQLSetConnectAttr(ghConnection, SQL_ATTR_TXN_ISOLATION, (SQLPOINTER)SQL_TXN_READ_COMMITTED , SQL_IS_INTEGER)))
// {
// GetSQLError();
// return 8;
// }
if(lbUseDSN)
{
int iReturn = ::SQLConnect(ghConnection,
(SQLCHAR*)"LocalCPR",
SQL_NTS,
(SQLCHAR*)"sa",
SQL_NTS,
(SQLCHAR*)"password1",
SQL_NTS);
if(!SQL_SUCCEEDED(iReturn))
{
GetSQLError();
return 8;
}
}
else
{
if(!SQL_SUCCEEDED(SQLDriverConnect(ghConnection,
NULL,
(SQLCHAR*)"DSN=LocalCPR;UID=sa;PWD=password1;",
SQL_NTS,
lszOutConnectString,
1024,
&llReturnLength,
SQL_DRIVER_NOPROMPT)))
{
GetSQLError();
return 8;
}
}
SQLAllocStmt(ghConnection, &ghStatement);
//If you set the isolation after you open the connection, you see the problem.
if(!SQL_SUCCEEDED(::SQLSetConnectAttr(ghConnection, SQL_ATTR_TXN_ISOLATION, (SQLPOINTER)SQL_TXN_READ_COMMITTED , SQL_IS_INTEGER)))
{
GetSQLError();
return 8;
}
return 0;
}
/**********************************************
* Disconnect
**********************************************/
long Disconnect()
{
if(ghStatement)
{
if(!SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_STMT, ghStatement)))
{
GetSQLError();
return 8;
}
ghStatement = NULL;
}
if(ghConnection)
{
::SQLDisconnect(ghConnection);
if(!SQL_SUCCEEDED(SQLFreeHandle(SQL_HANDLE_DBC, ghConnection)))
{
GetSQLError();
return 8;
}
ghConnection = NULL;
}
return 0;
}
/**********************************************
* ExecuteProcedure
**********************************************/
int ExecuteProcedure()
{
SQLINTEGER mlIndicator = 0;
SQLRETURN lnSqlRetCd = SQL_SUCCESS;
::SQLFreeStmt(ghStatement, SQL_CLOSE);
::SQLFreeStmt(ghStatement, SQL_UNBIND);
/*****************************************************************/
/* Execute Procedure
/*****************************************************************/
RETCODE llDbRetCd = SQLExecDirect(ghStatement, (SQLCHAR*)"SELECT * From Table1", SQL_NTS);
if((llDbRetCd != SQL_SUCCESS) && (llDbRetCd != SQL_SUCCESS_WITH_INFO))
{
GetSQLError();
return 8;
}
/*****************************************************************/
/* Bind return Value
/*****************************************************************/
char lszReturnBuf[300];
SDWORD lSts;
llDbRetCd = SQLBindCol(ghStatement, 1, SQL_C_TCHAR, &lszReturnBuf, 300, &lSts);
if ((llDbRetCd != SQL_SUCCESS) && (llDbRetCd != SQL_SUCCESS_WITH_INFO))
{
GetSQLError();
return 8;
}
/*****************************************************************/
/* Fetch Result
/*****************************************************************/
llDbRetCd = SQLFetch(ghStatement);
if ((llDbRetCd != SQL_SUCCESS) && (llDbRetCd != SQL_SUCCESS_WITH_INFO))
{
GetSQLError();
return 8;
}
printf("Output Value : %s\n",lszReturnBuf);
return 0;
}
/**********************************************
* GetSQLError
**********************************************/
void GetSQLError()
{
long llDbErrCd = 0;
short llRetMsgLen = 0;
char lszSqlErrMsg[255];
char lszSqlMsg[255];
SQLError(ghEnvironment,
ghConnection,
ghStatement,
(SQLCHAR*) lszSqlErrMsg,
&llDbErrCd,
(SQLCHAR*) lszSqlMsg,
255,
&llRetMsgLen);
printf(lszSqlErrMsg);
printf(lszSqlMsg);
}