ActiveX Data Objects (ADO) In Visual C++ - The Myriad of Data Access Technologie

Started by ganeshbala, Apr 21, 2008, 12:59 PM

Previous topic - Next topic

ganeshbala

The Myriad of Data Access Technologies

Applications are created to interact with data sources. When I say data source, I could mean excel sheets, indexed sequential data files, text files etc. Applications use different data access techniques to extract data from data sources. These techniques should be easy to use, and there mustn't be complex deployment issues associated with them. They should perform well in terms of using the smallest amount of processing power.

These issues led to the development of Universal Data Access (UDA) by Microsoft. UDA was based on COM and aimed to provide high performance data access to various data sources.

Even today, we have various data access technologies available. Some of them are:

    * ODBC (Open Database Connectivity): ODBC is a set of programming API's, which allows you to connect to a variety of data sources. Prior to ODBC we used to have DB-Libraries. The one flaw with DB-Libraries was that they were optimized to access data from a specific source, which made the application very dependent on the database used. On the other hand, ODBC could interact with various data sources using a common set of code.
    * DAO (Data Access Objects): DAO was a technology that was used to extract data from Jet Databases.
    * RDO (Remote Data Objects): RDO was a thin layer of API over ODBC. It was somewhat like an add-on for ODBC.
    * OLEDB: OLEDB is a system level API created by Microsoft, which uses its Universal Data Access strategy. It can extract data from relational and non-relational data sources.
    * ADO (ActiveX Data Objects): ADO is an enhanced version of DAO and RDO. ADO uses the OLEDB technology to gain access to any kind of data. You can interact with OLEDB directly but that would be difficult in any language that doesn't support pointers, such as Visual Basic. As OLEDB is at the system level, you would have to take care of many things like memory management, object creation and destruction and other system level purposes. ADO is entirely based on COM. It's a high level interface for using OLEDB. ADO provides us with an object oriented API to interact with a data source.

ADO consists mainly of three objects. The Connection, Command and RecordSet Objects:

Connection: This object is responsible for the connection to the data source. It encapsulates the details of a connection to the data source. You would have to supply the necessary details to this object in order to connect to the data source. All this information is bundled into one line called the ConnectionString. The open method of the Connection object accepts the ConnectionString as a parameter.

Command: This object is responsible for executing SQL statements and stored procedures.

Recordset: This object is responsible for storing the results returned by the data source. The recordset object also maintains all locking issues at the program level, NOT at the database level. Again, the data in the record set can be manipulated which in turn will be manipulated in the database.

Smart Pointers
I would also like to explain another concept before we proceed. It's about something called smart pointers. Smart pointers were made primarily to make programming a lot simpler. A smart pointer is a class that contains a pointer to another object. When you make an object of the smart pointer and call its methods, you are actually calling the methods of the interface, which is encapsulated in the smart pointer.

The smart pointer overrides the -> operator, which we use to call its methods. The smart pointer would ask you for the CLSID of the class which we want to use. Calling the CoCreateInstance method to create the object and other information related to creating the object is all encapsulated.

If smart pointers sound confusing then hopefully the code in the next couple of pages in this article will help to explain how they work.

Before you proceed, make sure you have worked with Visual C++ before to understand the following steps.