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.

BUG: Jet ODBC Driver Leaks Handle on Opening and Closing the Connection


View products that this article applies to.

This article was previously published under Q293890

↑ Back to the top


Symptoms

The Microsoft ODBC Driver for Access leaks handles and threads upon opening and closing the connection. This problem is observed in drivers that ship with MDAC 2.5, 2.5 SP1, and Jet 4.0 SP5.

↑ Back to the top


Resolution

To work around this problem, do not open and close the environment handle (henv) inside the loop.

Alternatively, you can load Msjet40.dll at the begining of your program to resolve this issue:
LoadLibrary("MSJET40.DLL")
				

↑ Back to the top


Status

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

↑ Back to the top


More information

Steps to Reproduce Behavior

  1. Copy the following code to your Microsoft Visual C++ project:
    #include <windows.h>
    #include <sql.h>
    #include <sqlext.h>
    #include <stdio.h>
    
    void main(void)
    {
        SQLHENV henv;
        SQLHDBC hdbc;
        SQLRETURN nstatus;
    	SQLCHAR szConnect[1024];
    	SQLSMALLINT cbConnString;
    
    for(int k =0;k<500;k++)
    {	
    	nstatus = SQLAllocHandle(SQL_HANDLE_ENV,NULL,&henv);
    	nstatus = SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION,(SQLPOINTER) SQL_OV_ODBC3,0);
    	nstatus = SQLAllocHandle(SQL_HANDLE_DBC,henv,&hdbc);
    	nstatus = SQLDriverConnect(hdbc,NULL,						
    		(SQLCHAR*) "Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Program Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB", 
    		SQL_NTS, szConnect, 1024, &cbConnString, SQL_DRIVER_NOPROMPT);
    
    	nstatus = SQLDisconnect(hdbc);
    	nstatus = SQLFreeHandle(SQL_HANDLE_DBC,hdbc);
    	nstatus = SQLFreeHandle(SQL_HANDLE_ENV,henv);
    }
     	printf("Done");
    } 
    
    					
  2. Point it to the MDB file on your computer.
  3. In Task Manager, add counters for handle count and thread count.
  4. Build and then run your code. You will see the thread and handle leak in Task Manager.

↑ Back to the top


Keywords: KB293890, kbnofix, kbjet, kbbug

↑ Back to the top

Article Info
Article ID : 293890
Revision : 3
Created on : 10/17/2003
Published on : 10/17/2003
Exists online : False
Views : 448