DAO External: Opening External Databases Directly

OverviewHow Do IFAQSampleODBC Driver List

This article explains how to open a table in an ODBC data source directly, rather than by attaching the table to a Microsoft Jet (.MDB) database. For a general discussion of external data sources, see the article DAO External: Working with External Data Sources.

Important   If you are working with an ODBC data source, it is recommended that you attach the external table to your Microsoft Jet database instead of opening it directly as described in this article. Doing so significantly improves performance. For information about attaching tables, see the article DAO External: Attaching External Tables.

To open an external table directly using the MFC DAO classes

  1. Open the external data source.

    Construct a object, or obtain a pointer to one (from an open recordset object, for example) and call the object's member function. Supply appropriate connection information for the data source.

  2. Create a recordset for the external table.

    Construct a object, basing the recordset on the CDaoDatabase object for the external table.

  3. Work with the recordset as you would with any recordset. But note that if you are working with ODBC performance may not be as good as if you had attached the table instead.

Note   Creating the recordset requires that you supply the external table name. Usually, you'll do this when you create your CDaoRecordset-derived class with either AppWizard or ClassWizard. The external table name is a table name, not a filename, so you don't use the filename extension. This is true for all external data sources, such as dBASE and FoxPro, in which tables are stored as individual disk files.

Important   When you specify the recordset type (table-type, dynaset-type, or snapshot-type), be aware that you can't use a table-type recordset with ODBC data sources.

For information about the preferred alternative to this procedure, see the article DAO External: Attaching External Tables.

See Also   DAO: Where Is..., DAO External: Working with External Data Sources, DAO External: Attaching External Tables