Microsoft KB Archive/281735

= BUG: &quot;Memory could not be read&quot; Error Occurs with ODBC Under High Stress =

Article ID: 281735

Article Last Modified on 5/12/2003

-

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:

&quot;YourApp.EXE - Application Error: The instruction at '0x1f8148d9' referenced memory '0x1f8148d9'. The memory could not be 'read'.&quot;



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.



Steps to Reproduce Behavior
 Create a Win32 DLL named &quot;TestDll&quot; that exports a function named &quot;Function1&quot; that connects to and disconnects from a database using ODBC. Create a Win32 console application named &quot;Application1&quot; that calls LoadLibrary, Function1, and FreeLibrary of TestDll. Create another Win32 console application named &quot;Application2&quot; that spawns 50 instances of Application1 in an infinite loop. After ten or fifteen minutes, the following error message is generated:

&quot;Application1.EXE - Application Error: The instruction at '0x1f8148d9' referenced memory '0x1f8148d9'. The memory could not be 'read'.&quot;



Additional query words: instruction perfmon odbc32 access violation

Keywords: kbbug KB281735

-

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

© Microsoft Corporation. All rights reserved.