Microsoft KB Archive/293890

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

Article ID: 293890

Article Last Modified on 10/17/2003

-

APPLIES TO


 * Microsoft Data Access Components 2.5
 * Microsoft Open Database Connectivity Driver for Access 4.0

-



This article was previously published under Q293890



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.



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(&quot;MSJET40.DLL&quot;)



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



Steps to Reproduce Behavior
  Copy the following code to your Microsoft Visual C++ project:
 * 1) include 
 * 2) include 
 * 3) include 
 * 4) include 

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*) &quot;Driver={Microsoft Access Driver (*.mdb)};DBQ=C:\\Program Files\\Microsoft Visual Studio\\VB98\\NWIND.MDB&quot;,         SQL_NTS, szConnect, 1024, &cbConnString, SQL_DRIVER_NOPROMPT);

nstatus = SQLDisconnect(hdbc); nstatus = SQLFreeHandle(SQL_HANDLE_DBC,hdbc); nstatus = SQLFreeHandle(SQL_HANDLE_ENV,henv); }   printf(&quot;Done&quot;); }

 Point it to the MDB file on your computer. In Task Manager, add counters for handle count and thread count. Build and then run your code. You will see the thread and handle leak in Task Manager.</li></ol>

Keywords: kbbug kbnofix kbjet KB293890

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.