Microsoft KB Archive/306579

= FIX: ODBC application terminates when you press CTRL+ALT+DEL =

Article ID: 306579

Article Last Modified on 7/28/2004

-

APPLIES TO

 Microsoft Open Database Connectivity Driver for Access 4.0, when used with:  Microsoft Windows NT 4.0

 Microsoft Windows 2000 Standard Edition 

-



This article was previously published under Q306579



SYMPTOMS
Using ODBC to access a datasource through the Microsoft Jet 4.0 ODBC driver, you may see the following behavior. When the application is running, if the user presses CTRL+ALT+DEL to display the Windows NT Security dialog box and then dismisses the dialog box by clicking Cancel, the ODBC application may terminate unexpectedly. This behavior can also occur when the screensaver is activated and then deactivated.



CAUSE
This is caused by a known issue with Microsoft Jet 4.0 versions that are earlier than Service Pack 6. The problem occurs when the Jet engine is unloaded from memory before all its background worker threads have been shut down. With an ODBC application, this can occur if all ODBC environment handles are freed before the application terminates.



WORKAROUND
Do not free all ODBC environment handles in the application until it is time for the application to be unloaded.

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section. This bug was corrected in Microsoft Jet 4.0 Database Engine Service Pack 6 and later. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:

239114 How to obtain the latest service pack for the Microsoft Jet 4.0 Database Engine

<div class="moreinformation_section">

MORE INFORMATION
To reproduce the problem, the application must open an ODBC environment handle (HENV), use that handle, and then free the handle using SQLFreeHandle or SQLFreeEnv. After the last handle is freed, and the application is still loaded, if CTRL+ALT+DEL is pressed or the screensaver is activated, the application terminates unexpectedly.

Steps to reproduce the behavior
<ol>  Create a Win32 console application and paste the following code:
 * 1) include <windows.h>
 * 2) include <sql.h>
 * 3) include <sqlext.h>
 * 4) include <stdio.h>

void main {      SQLHENV     henv = SQL_NULL_HENV; SQLHDBC    hdbc1 = SQL_NULL_HDBC; RETCODE retcode; if (!SQL_SUCCEEDED(retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv))) { printf(&quot;SQLAllocHandle(ENV) failed.\n&quot;);} if (!SQL_SUCCEEDED(retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER))) { printf(&quot;SQLSetEnvAttr failed.\n&quot;);} if (!SQL_SUCCEEDED(retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1))) { printf(&quot;SQLAllocHandle(DBC) failed.\n&quot;);} if (!SQL_SUCCEEDED(retcode = SQLConnect(hdbc1, (SQLCHAR*)&quot;reidpubs&quot;, SQL_NTS, (SQLCHAR*)&quot;&quot;, SQL_NTS, (SQLCHAR*)&quot;&quot;, SQL_NTS))) { printf(&quot;SQLConnect failed.\n&quot;);} if (!SQL_SUCCEEDED(retcode = SQLDisconnect(hdbc1))) { printf(&quot;SQLDisconnect failed.\n&quot;);} if (!SQL_SUCCEEDED(retcode = SQLFreeHandle(SQL_HANDLE_DBC, hdbc1))) { printf(&quot;SQLFreeHandle(DBC) failed.\n&quot;);} if (!SQL_SUCCEEDED(retcode = SQLFreeHandle(SQL_HANDLE_ENV, henv))) { printf(&quot;SQLFreeHandle(ENV) failed.\n&quot;);} hdbc1 = SQL_NULL_HDBC; henv = SQL_NULL_HENV; char ch; printf(&quot;enter a key to close\n&quot;); scanf(&ch);

}                   </li> In the code, replace &quot;reidpubs&quot; with the name of a data source name (DSN) to a Microsoft Access database.</li> Run the application. When &quot;enter a key to close&quot; is displayed on the console, press CTRL+ALT+DEL or let the screensaver start.</li></ol>

Keywords: kbbug kbdatabase kbdriver kbjet kbnofix KB306579

-

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

© Microsoft Corporation. All rights reserved.