CatDB Sample: Data Source Schema Browser

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 the changes from the MFC sample are surgical. This sample uses the 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.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

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. 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 OnUpdatefunction moves through the records in the database and accesses the CTables and CColumns classes for data.

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, CSession, CTables

The sample demonstrates the following functions:

CDataSource::Open

See Also

Other Resources

ATL Samples