Home | Overview | How Do I | FAQ | Sample | Tutorial | ODBC Driver List
This article explains the best approaches to using the MFC DAO classes with external data sources, primarily ODBC data sources.
Topics include:
Aside from working with a Microsoft Jet (.MDB) database on your local machine, you can use the MFC DAO classes to access external data of several kinds. External data includes data located in:
The discussion in this and related articles applies to the following external data sources:
The MFC DAO classes give you two choices for accessing tables stored in external data sources. You can either:
-or-
When you attach a table, it is treated in most respects as if it were a Microsoft Jet database table in the current database — except that you can't modify the table's schema or open a table-type recordset on it. The connection information to the external data source is stored with the table definition, making it easy to open recordsets on the table. The data is still stored in the external data source, however. For information on attaching tables, see the article DAO External: Attaching External Tables.
Tip If you attach a table from within Microsoft Access, you can then use the table from MFC.
When you open a table directly, you specify the connection information each time you open the external database. This can involve communication overhead. For information on opening tables directly, see the article DAO External: Opening External Databases Directly.
Important In most cases, attaching a table is a faster method for accessing external data than opening a table directly, especially when the table is in an ODBC data source. If possible, it's best to attach external tables rather than to open them directly. If you do open a table in an ODBC data source directly, keep in mind that performance will be significantly slower.
To attach or open a data source on a network, you must have access to the server and share and to the external table as well as appropriate permissions for access to the data, if applicable.
Keep in mind that external tables are not actually in your Microsoft Jet database. Each time you view data in an external table, your program must retrieve records from another file. This can take time, particularly if the table is an ODBC data source.
ODBC performance is optimal if you attach tables instead of opening them directly, and if you retrieve and view only the data you need. Restrict your queries to limit results and avoid excessive scrolling through records. For more performance tips, see the article DAO External: Improving Performance with External Data Sources.
For a discussion of why performance suffers with external data sources, particularly ODBC data sources, see the topic "Accessing External Databases with DAO" in DAO Help.
Attaching external tables to a Microsoft Jet database is generally more efficient than opening the external data source directly. However, there still might be circumstances under which you would prefer to open the external database directly. They include the following:
For more information, including procedures, see the following articles (in the recommended reading order):
An additional source of information is the Advanced Topics book from the Microsoft Access Developer's Toolkit. You'll need to translate Microsoft Access Basic examples to MFC, but the chapter on Accessing External Data gives detailed advice on using external data sources such as Microsoft FoxPro, dBASE and Paradox.
For related information, see the topic "Accessing External Databases with DAO" in DAO Help.
For information about accessing specific external data sources, see the following topics in DAO Help:
See Also DAO: Where Is...