Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

FIX: Access Violation Occurs with ODBC BCP and Connection Pooling


View products that this article applies to.

This article was previously published under Q327723

↑ Back to the top


Symptoms

In an application that uses the Microsoft SQL Server-specific bulk-copy (BCP) ODBC application programming interface (API) extensions, and that has ODBC connection pooling turned on, an access violation occurs when you execute functions such as bcp_exec and bcp_batch.

↑ Back to the top


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 that contains this hotfix.

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 about support costs, visit the following Microsoft Web site: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 typical support costs will apply to additional support questions and issues that do not qualify for the specific update in question.

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.
   Date         Version         Size           File name
   --------------------------------------------------------
   29-Aug-2002    2000.81.9001.1  356,352 bytes  Sqlsrv32.dll 		
   29-Aug-2002    2000.81.9001.1  90,112 bytes   Sqlsrv32.rll
   29-Aug-2002    2000.81.9001.1  24,576 bytes   Odbcbcp.dll
				

↑ Back to the top


Workaround

Turn off connection pooling for the ODBC environment handle that is associated with the ODBC connection that is used for the bulk-copy calls.

↑ Back to the top


Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article.

↑ Back to the top


More information

Steps to Reproduce the Behavior

  1. Use the following SQL statement to create the test table in your SQL Server database:
    CREATE TABLE bcptest(col1 integer)
  2. To reproduce the access violation, compile and run the following code:

    Note: Change the connection string to refer to your SQL Server.
    #include <windows.h>
    #include <sql.h>
    #include <sqlext.h>
    #include <odbcss.h>
    #include <stdio.h>
    
    int main(int argc, char* argv[])
    {
    	SQLHENV henv;
    	SQLHDBC hdbc;
    
    	//To workaround the problem, remove the following call:
    	SQLSetEnvAttr(NULL, SQL_ATTR_CONNECTION_POOLING, (SQLPOINTER)SQL_CP_ONE_PER_DRIVER, 0);
    	SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
    	SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, 0); 
    	//If connection pooling has already been turned on globally, you can turn it off explicitly as follows:
    	//retcode = SQLSetEnvAttr(henv, SQL_ATTR_CONNECTION_POOLING, SQL_CP_OFF, 0);
    	SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc); 
    
    	// Enable bulk copy before to connecting on allocated hdbc.
    	SQLSetConnectAttr(hdbc, SQL_COPT_SS_BCP, (SQLPOINTER) SQL_BCP_ON, SQL_IS_INTEGER);
    
    	char szConnStrOut[4096];
    	SQLSMALLINT cbConnStrOut = 0;
    
    	//Connect to SQL Server.
    	SQLRETURN sqlReturn = SQLDriverConnect(hdbc, NULL, (SQLCHAR*)"DRIVER={SQL Server};SERVER=myServer;UID=myUID;PWD=myPWD;DATABASE=myDB;", SQL_NTS, (SQLCHAR*)szConnStrOut,  SQL_NTS, &cbConnStrOut, SQL_DRIVER_NOPROMPT);
    	
    	//Initialize bulk copy operation.
    	sqlReturn = bcp_init(hdbc, "bcptest", NULL, NULL, DB_IN);
    
    	//Allocate statement handle for bcp operations.
    	HSTMT bcpStatement;
    	SQLAllocHandle(SQL_HANDLE_STMT,hdbc, &bcpStatement);
    
    	//Bind the column and send a row of data.
    	int i = 77;
    	bcp_bind(hdbc, (LPCBYTE) &i, 0, sizeof(DBINT), NULL, 0, SQLINT4, 1);
    	bcp_sendrow(hdbc);
    	
    	//The following call causes the access violation.
    	//If successful, one row is inserted.
    	bcp_batch(hdbc);  
    	bcp_done(hdbc);
    
    	SQLFreeHandle(SQL_HANDLE_STMT, bcpStatement);
    	SQLDisconnect(hdbc);
    	SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
    	SQLFreeHandle(SQL_HANDLE_ENV, henv);
    }
    					

↑ Back to the top


Keywords: KB327723, kbhotfixserver, kbqfe, kbfix, kbbug

↑ Back to the top

Article Info
Article ID : 327723
Revision : 5
Created on : 10/11/2005
Published on : 10/11/2005
Exists online : False
Views : 462