Managing database operations using ADO and C++

by Patrick Mancier

This series of articles will detail how to use Microsoft Active Data Objects (ADO) and C++ to manage database operations. ADO can be used very generically for many different database platforms but for the purposes of this article the syntax for SQL tables and procedures will be in Microsoft SQL server format. The code presented here is not production quality code; it simply serves as an example for creating and designing a manager class for accessing a database using ADO and C++. Things like checking return codes, logging into a debug log, and memory management are not within the scope of this article or its code.

Part 1: Introduction to SQL

Highlights in simple terms the basic SQL operations that the examples will perform and introduce the reader to some simple SQL syntax. The syntax is kept in T-SQL whenever possible but does favor MS-SQL syntax in the procedural logic.

Part 2: Introduction to ADO

Gives the reader an overview of ADO and explain how to set up the compiler to use the various ADO objects.

Part 3: ADO Wrapper Classes

Goes over in detail how to create an ADO wrapper set of classes to make it easier to design and use the main ADO C++ manager class.

Part 4: Creating an ADO based C++ management class

Detailed design discussion of how to implement the ADO based C++ management class called CADOManager based on the previous sections of the article. It will show how to seamlessly use the wrapper classes in order to create the manager class.

Part 5: Using the CADOManager in practice

Shows how to use the CADOManager in code and gives several examples of various table operations and using it to call user defined queries and procedures.

Assumptions with regards to the knowledge of the reader

  • Knowledge of SQL and database design and procedural logic
  • Knowledge of MS-SQL server and procedure syntax
  • Intermediate C++ skills
  • Familiarity with COM
  • Some version of Visual Studio 2005, 2008 installed. Visual C++ 6.0 will probably work but was not used in this article.
  • This article uses SQL Express 2005 as the database server choice. SQL Express 2008 may or may not work

Addendum: Sample Code

Code and an executable to illustrate the examples in the previous sections.

Microsoft SQL Express Server

In order to use the SQL examples in this article, the author chose MS-SQL server as the platform. SQL Express has some minor limitations including database size and number of supported remote connections. These limitations will not interfere with the scope of this article. It is highly recommended that the reader take the time to install this if no other SQL server is available.

When installing SQL Express, one thing that happens is that the remote TCP/IP option is turned off by default. This should be turned back on after installation. Ideally one should put the server on a dedicated computer to remotely access it but if you need to install it locally you should still turn this on because it will make your transition from a local to a remote installation easier. You can opt to keep it off but in your connection string you will need to specify .local. for your SQL server.

The other thing to keep in mind is to download and install the SQL Express with Tools. This version comes with the express version of the SQL Management Studio. This tool will allow the user to more easily maintain and work with the installed databases. The management tool will make it easy to browse various install databases, view table data, and create procedures. The management tool uses what is called a .query window. in order to do various SQL operations. It makes it very easy to run various database operations such as DELETE, INSERT, SELECT, UPDATE right from a query window.

Microsoft specific links

Microsoft is always changing their download links so it would be of benefit to use a search engine to locate and download the software. The links provided are accurate as of the time of this writing.

Complete documentation for ADO


Download ADO (MSXML4.0 Service Pack 3 (SP3))

A list of column types in a table

Microsoft SQL server 2005 Overview

Microsoft SQL Server Management Studio Express

Microsoft SQL Server 2005 Express Edition Toolkit

Microsoft "Express" suite (2008) (SQL Server, Visual (Basic, C#, C++, Web Developer)