SAMPLE: Asynchronous MFC ODBC Database Processing Using ThreadsLast reviewed: July 2, 1997Article ID: Q166111 |
The information in this article applies to:
SUMMARYThis sample shows how to provide asynchronous database processing by running a database query on a secondary thread. The following self-extracting file is available for download from the Microsoft Software Library:
~ Mtdb.exe (size: 38179 bytes)NOTE: Use the -d option when running MTDB.EXE to decompress the file and re- create the proper directory structure. For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q119591 TITLE : How to Obtain Microsoft Support Files from Online Services MORE INFORMATIONBeginning with version 4.2 of the MFC database classes, the ability to set the processing mode to asynchronous using CDatabase::SetSynchronousMode() has become obsolete. The MFC ODBC classes now use only synchronous processing. The following functions, which were used with asynchronous processing in versions before 4.2, are also obsolete: CDatabase::InWaitForDataSource(), CDatabase::OnWaitForDataSource() and CRecordset::OnWaitForDataSource(). One way to implement asynchronous database processing with MFC 4.2 and above is to run your database query on a secondary worker thread. The MTDB sample illustrates this by having each document open the corresponding recordset on a new worker thread. When the user presses the "Cancel Query" button, the primary thread cancels processing on the secondary thread. As with any multi-threaded database application, each component must be thread-safe. Specifically, you must be using a thread-safe ODBC driver, such as the Microsoft SQL Server ODBC driver, for this application to work correctly. This sample uses the Student Registration database, which can be created for SQL Server using the STDREG sample program that is included with Visual C++. |
Keywords : kbprg kbsample MfcDatabase MfcThreadIss
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |