CatDB: Data Source Schema Browser

Click to open or copy the CatDB project files.

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.

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 Template 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 Template 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.

You can use this sample with the ODBC provider and with the Microsoft Access 97 and Microsoft SQL Server 6.5 databases. If you have the OLE DB SDK installed, to run this sample you must set up the OLE_DB_NWind_Jet and OLE_DB_NWind_SQL data services using the ODBC icon in the control panel.