FIX: ODBC application terminates when you press CTRL+ALT+DEL (306579)



The information in this article applies to:

  • Microsoft ODBC Driver for Access 4.0, when used with:
    • the operating system: Microsoft Windows NT 4.0
    • the operating system: Microsoft Windows 2000

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.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" 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

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

  1. Create a Win32 console application and paste the following code:
    #include <windows.h>
    #include <sql.h>
    #include <sqlext.h>
    #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("SQLAllocHandle(ENV) failed.\n");}
    	if (!SQL_SUCCEEDED(retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER))) { printf("SQLSetEnvAttr failed.\n");}
    	if (!SQL_SUCCEEDED(retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1))) { printf("SQLAllocHandle(DBC) failed.\n");}
    	if (!SQL_SUCCEEDED(retcode = SQLConnect(hdbc1, (SQLCHAR*)"reidpubs", SQL_NTS, (SQLCHAR*)"", SQL_NTS, (SQLCHAR*)"", SQL_NTS))) { printf("SQLConnect failed.\n");}
    	if (!SQL_SUCCEEDED(retcode = SQLDisconnect(hdbc1))) { printf("SQLDisconnect failed.\n");}
    	if (!SQL_SUCCEEDED(retcode = SQLFreeHandle(SQL_HANDLE_DBC, hdbc1))) { printf("SQLFreeHandle(DBC) failed.\n");}
    	if (!SQL_SUCCEEDED(retcode = SQLFreeHandle(SQL_HANDLE_ENV, henv))) { printf("SQLFreeHandle(ENV) failed.\n");}
    	hdbc1 = SQL_NULL_HDBC;  
    	henv = SQL_NULL_HENV;
    	char ch;
    	printf("enter a key to close\n");
    	scanf(&ch);
    
    }
    					
  2. In the code, replace "reidpubs" with the name of a data source name (DSN) to a Microsoft Access database.
  3. Run the application. When "enter a key to close" is displayed on the console, press CTRL+ALT+DEL or let the screensaver start.

Modification Type:MajorLast Reviewed:7/28/2004
Keywords:kbBug kbDatabase kbDriver kbJET kbnofix KB306579 kbAudDeveloper