Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
CatDB Sample: Data Source Schema Browser

CatDB Sample: Data Source Schema Browser 

Download sample

CatDB is ported from the MFC ODBC Catalog application. The application displays the schema information, such as tables and columns, of OLE DB providers. It is easy for you to track the differences between this sample and the MFC ODBC Catalog sample, because all of the changes from the MFC sample are surgical. This sample makes use of the CEnumerator, CDataSource, CSession, and schema rowset classes.

Security noteSecurity Note

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

Building and Running the Sample

You can use this sample with the ODBC provider and with the Microsoft Access 97 and Microsoft SQL Server 6.5 databases (or later versions). To run this sample, you must have the MDAC SDK installed.

To build and run this sample

  1. Open the solution file CatDB.sln.

  2. From the Build menu, click Build.

  3. From the Debug menu, click Start Without Debugging.

    A dialog box will appear, titled "CatDB - [No data source selected]."

  4. Click Open from the File menu. The Data Link Properties dialog box will appear. On the Provider tab, select Microsoft OLE DB Provider for SQL Server (or Microsoft Jet 4.0 OLE DB Provider). On the Connection tab, select the Northwind database.

    The table information will appear in the dialog box's window. The dialog box title will change to the database name.

How the Sample Works

The code to enumerate the providers, connect to a data source, and create a session is in the CCatDBDoc::OnOpenDocument function. The code to open the schema rowsets is in CCatDBDoc::FetchTableInfo and CCatDBDoc::FetchColumnInfo. Both FetchTableInfo and FetchColumnInfo use the OLE DB Templates schema rowset classes, CTables and CColumns. The code to display the schema information is in CCatDBView::OnUpdate. The OnUpdate function moves through the records in the database and accesses the CTables and CColumns classes for data.

This sample demonstrates how to enumerate the OLE DB providers. CEnumSourcesDlg provides support to recursively display and connect to the data sources. The dialog box uses the OLE DB Templates CEnumerator class. To connect to the data source, CEnumSourcesDlg returns an LPMONIKER value for the selected data source. CDataSource::Open then takes this LPMONIKER value and performs the connection.


Some of the samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.


The sample demonstrates the following classes:

CColumns, CDataSource, CEnumerator, CSession, CTables

The sample demonstrates the following functions:


See Also

Other Resources

ATL Samples

Community Additions

© 2015 Microsoft