DynamicConsumer Sample: Uses Dynamic Accessor and Schema Rowset Classes to Read Metadata from a Database

The DynamicConsumer sample is a simple console application that allows you to connect to any data source and select a table or stored procedure. If you select a stored procedure, the sample application will prompt you to enter the values for parameters. It then executes a command to display the data in the result rowset.

Security noteSecurity Note

This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.

To get samples and instructions for installing them:

To access samples from Visual Studio

  • On the Help menu, click Samples.

    By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.

  • For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.

Building and Running the Sample

To build and run this sample

  1. Open the solution file DynamicConsumer.sln.

  2. From the Build menu, click Build.

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

  4. A console window will appear, prompting you to specify which kind of accessor to use. Enter a number to specify an accessor type. Other specification menus will follow, depending on your choice.

  5. When you are finished with the menu selections, the Data Link Properties dialog box will appear. On the Provider tab, select Microsoft OLE DB Provider for SQL Server. On the Connection tab, select a database such as Northwind.

  6. When you have selected a data source, the console prompts you to specify the table from which you want to print out data. When you do so, the table's data displays in the console.

How the Sample Works

The sample uses schema rowset classes to read metadata from the data source. Metadata is any information about a data source other than the data stored in the database, such as column names, column data types, table names, or stored procedures. DynamicConsumer uses the schema rowset classes CTables, CProcedures, and CProcedureParameters to select the table or procedure and to build a SQL command string dynamically. The sample also uses the following accessor classes:

  • CDynamicAccessor (demonstrates the various ways to handle BLOB data)

  • CDynamicStringAccessor

  • CXMLAccessor

  • CDynamicParameterAccessor

Keywords

The sample demonstrates the following classes:

CDynamicAccessor, CDynamicParameterAccessor, CDynamicStringAccessor, CProcedureParameters, CProcedures, CTables, CXMLAccessor

See Also

Other Resources

ATL Samples