<!-- Download Links -->
Most of us know that OLEDB is the latest database technology that provides
fast data access on the windows platform. However, many C++ programmers
tend to avoid using raw OLEDB and prefer ADO in
their development process. There are two main reasons for this. First
of all, OLEDB interfaces (which are COM interfaces) are extremely complex
and sparsely documented. They are neither convenient nor
developer-friendly. So, we are left with other choice : use ATL consumer
templates for OLEDB. These template classes are very powerful and high
performance. However, they lack the flexibility and rich functionality
provided by ADO. Many times one has to resort to ADO for some database
operations such as binding a rowset to datagrid or other controls. This is
because there is no easy way to bind a OLEDB rowset to a control.
This article presents a set of classes that are extended from ATL consumer
template classes for OLEDB. While these classes provide added flexibility
and functionality similar to ADO, they still retain the power and
performance of consumer template classes. Here, in this article, I will present
only a subset of a complete libray that we have built for commercial
 The Connection object :
In OLEDB consumer templates, you have to deal with two classes for
maintaining database connection and transaction purposes : CDataSource and
CSession. This is sometimes confusing. Instead, we created a single class
called CSypODLConnection that is very much like Connection object in ADO.
This class combines the functionality of database connection and
transaction maintenance. The use of this class is pretty simple :
CSypODLConnection m_Cnn; object
m_Cnn.Open("CONNECTION STRING", "UID", "PWD");
You can also use transactions on this object like ADO connection
ransaction(); -- Code ---
Also, like ADO connection object, we have provided
Execute method for executing action queries.<!-- end the block of source code -->
m_Cnn.Execute("DELETE FROM Customer WHERE CustomerID = 5");
 RecordBase, Exception, and
Similarly, we have also created a recordset class called
CSypODLRecordset, which wraps up CCommand and CTable comsumer template
classes. Those who have worked with these consumer template classes
know how tedious it is to check the HRESULT value after each method call.
Not only is it time-consuming to check HRESULT value at every point, but also it
is extremely difficult to get errors from IErrorInfo interface. In order to
solve this problem, we created two classes : an exception class and an
error-processing class. So, the code becomes very simple as shown below :
CSypODLRecordBase<CAccessor<CSalesManTableAccessor> > m_Rs;
m_Rs.Open("SalesMan", &m_Cnn, 1);
Essentially, if you already know ADO, this library will be easy to
understand and use. So, if you want to give your application a lightening speed
and high performance, use these classes.
Actually, there are so many features and so many classes
in the library that we can write a complete a book on it. However, due to lack of space and scope, I urge users to go through
the code which is self-explanatory. Besides, the classes we have included here are
only a subset of what is a complete, independent, and full-featured library. I
would also advise you to study the included sample, and see how easy it is to
use these classes. If you need a complete documentation, you may contact me
Known drawbacks and limitations
There seems to be bugs in some OLEDB providers that may affect some
of the functionality of this library. For some reason, the Update method and bookmarks fail with
certain providers. Also, this library is mostly tested with JET and
OleDb provider for ODBC.
If you decide to use this code
You are free to use or modify this code subject to the
- You must acknowledge us somewhere in your about box
or documentation, simple "Parts of code by..Sypram Technology" will be enough.
If you cannot (or don't want to) mention us, contact one of us at Sypram
Technology (www.sypram.com) personally.
- Do not remove copyright notices from the source and
- Do not publish any part of this code or article on
- We reserve exclusive right to update this page, as
well as provided source code. Please publish your modification and additions
on adjacent pages. We may add your modifications and/or additions to a future
update to the article and source with proper credit for your work.
If you have any other question or you need further
assistance, contact me at GNaik@SypramTech.com or GhanNaik@Yahoo.com.