Share via


ODBC Classes and Threads

OverviewHow Do IFAQSampleODBC Driver List

Beginning with MFC 4.2, there is multithreading support for the MFC ODBC classes. Note, however, that MFC does not provide multithreading support for the DAO classes.

The multithreading support for the ODBC classes has some limitations. Because these classes wrap the ODBC API, they are restricted to the multithreading support of the components on which they are built. For example, there are many ODBC drivers that are not thread-safe; therefore, the MFC ODBC classes will not be thread-safe if you use them with one of these drivers. You should verify whether your particular driver is thread-safe.

When creating a multithreaded application, you should be very careful in using multiple threads to manipulate the same object. For example, using the same CRecordset object in two threads may cause problems when retrieving data; a fetch operation in one thread may overwrite the data fetched in the other thread. A more common use of the MFC ODBC classes in separate threads would be to share an open CDatabase object across threads in order to use the same ODBC connection, with a separate CRecordset object in each thread. Note that you should not pass an unopened CDatabase object to a CRecordset object in another thread.

****Important   ****If you must have multiple threads manipulate the same object, you should implement the appropriate synchronization mechanisms, such as critical sections. Be aware that certain operations, such as Open, are not protected. You should be sure that these operations will not be called concurrently from separate threads.

For more information about creating multithreaded applications, see the article Multithreading Topics.

See Also   Database Topics (General)