Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

Symptoms

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:

IM006[Microsoft][ODBC Driver Manager] Driver's SQLSetConnectAttr failed

Note The ODBC Driver documentation mentions that the message is an information message. However, you receive the message as an error message.

This problem may occur when all the following conditions are true:

  • You make the connection with a data source name (DSN) by using the SQLConnect ODBC Driver API.

  • One of the default properties of the DSN (such as the Use ANSI nulls, paddings and warnings option) is disabled.

  • Connection pooling is enabled for the environment handle.

  • The Transaction Isolation Level attribute of the connection is set after you open the connection by using SQLConnect.

  • A database transaction is performed.

Workaround

To work around this problem, follow these steps:

  1. Disable the connection pooling option for the ODBC connection.

    Note Disabling connection pooling may affect the performance of your application.

  2. After you commit the transaction, do not turn on the auto commit option.

  3. Set the transaction isolation level before you open the ODBC connection.

  4. Use a DSN-less connection instead of obtaining the ODBC connection with a DSN.

Resolution

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:

http://support.microsoft.com/contactus/?ws=supportNote 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
 

Status

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.

More Information

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);
}

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

Was this information helpful?

What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×