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
| Security 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. |
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
Open the solution file CatDB.sln.
From the Build menu, click Build.
From the Debug menu, click Start Without Debugging.
A dialog box will appear, titled "CatDB - [No data source selected]."
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, 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.
| Note |
|---|
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. |
Keywords
The sample demonstrates the following classes:
CColumns, CDataSource, CEnumerator, CSession, CTables
The sample demonstrates the following functions:
CDataSource::Open