INFO: Thread Safety and the Access ODBC Driver

Last reviewed: May 12, 1997
Article ID: Q167907
The information in this article applies to:
  • Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2, 4.0, 4.0a, 4.1, 4.2, 5.0

SUMMARY

There are some limitations when you use the Access ODBC Driver in multi- threaded applications.

MORE INFORMATION

The Versions of the Access ODBC driver that shipped with versions 4.2 and earlier of Visual C++ (or as version 3.0 of the desktop drivers) has limitations when you use it in multithreaded applications. You cannot pass connection and statement handle values from one thread to another. This also means that CDatabase and CRecordset MFC objects cannot be shared between threads.

The reason for this is that the Jet database engine utilized VBA, which supports the Apartment Model of thread safety rather than free-thread safety. Although the Access ODBC Driver, internally, put a critical section around every call to the Jet engine, the use of VBA made the sharing of connection and statement handles unsafe. As long as the thread in the application that initiated a connection to the Access Driver is the only one that does work on that connection, everything is fine. However, it is not safe to pass the connection handle onto another thread and have that thread do work on that connection.

The multithreaded capabilities of the desktop drivers that ship with Visual C++ 5.0 (or as version 3.5 of the desktop drivers) have improved. It is now safe to share connection handles between threads. However, the thread that creates the connection must also free it. It is still not safe to share statement handles. This means that it is safe to share CDatabase objects but not CRecordset objects.


Keywords : MfcDatabase
Version : 2.0 2.1 2.2 4.0 4.0a 4.1 4.2 5.0
Platform : NT WINDOWS
Issue type : kbinfo


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: May 12, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.