BUG: "Memory could not be read" Error Occurs with ODBC Under High Stress (281735)



The information in this article applies to:

  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6
  • Microsoft Data Access Components 2.7

This article was previously published under Q281735

SYMPTOMS

Applications that call the LoadLibrary and FreeLibrary functions for a dynamic-link library (DLL) that uses Odbc32.dll may receive the following error message when multiple instances of the application are running under a heavily stressed environment:
"YourApp.EXE - Application Error: The instruction at '0x1f8148d9' referenced memory '0x1f8148d9'. The memory could not be 'read'."

CAUSE

Odbc32.dll generates a secondary thread to monitor the ODBC registry keys. When Odbc32.dll is unloading, it waits 100 milliseconds for the secondary thread to terminate. After 100 milliseconds, it unloads itself, even if the thread has not terminated.

In most scenarios, 100 milliseconds is enough time for the thread to terminate. However, if the CPU is under high stress, the secondary thread may still be running after Odbc32.dll is unloaded, which causes the error.

RESOLUTION

Remove the explicit FreeLibrary call for the DLL that is using Odbc32.dll.

STATUS

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

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a Win32 DLL named "TestDll" that exports a function named "Function1" that connects to and disconnects from a database using ODBC.
  2. Create a Win32 console application named "Application1" that calls LoadLibrary, Function1, and FreeLibrary of TestDll.
  3. Create another Win32 console application named "Application2" that spawns 50 instances of Application1 in an infinite loop.
  4. After ten or fifteen minutes, the following error message is generated:
    "Application1.EXE - Application Error: The instruction at '0x1f8148d9' referenced memory '0x1f8148d9'. The memory could not be 'read'."

Modification Type:MajorLast Reviewed:5/12/2003
Keywords:kbBug KB281735