Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame


Environment:  : VC++6 SP5, MDAC 2.5 and above


Most of us know that OLEDB is the latest database technology that provides fastest data access on 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 user interface operations such as binding a rowset to datagrid or other controls. This is because there is no direct way to bind an 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 like ADO, they still retain the power and performance of consumer template classes. Here, in this article, I present only a subset of a complete libray that we have built for commercial product development.

[1] Connection object : CSypODLConnection

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 :

// Define connection object
CSypODLConnection m_Cnn; 

// Connnect to database

You can also use transactions on this object like ADO connection object

m_Cnn.StartTransaction(); // Connnect to database
-- Code ---

Also, like ADO connection object, we have provided Execute method for executing action queries.

m_Cnn.Execute("DELETE FROM Customer WHERE CustomerID = 5");

[1] RecordBase, Exception, and Error classes

Similarly, we have also created a recordset class called CSypODLRecordBase, 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;
// Process data now
  m_Rs.Open("SalesMan", &m_Cnn, 1); // 1 indicates table
  while (!m_Rs.IsEOF())

catch(CSypODLException e)

Essentially, if you already know ADO, this library will be easiest 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. 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 directly.

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.

If you decide to use this code

You are free to use or modify this code subject to the following restrictions:

* 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 personally.

* Do not remove copyright notices from the source and header files.

* Do not publish any part of this code or article on other websites.

* 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.


Download demo project - 57 Kb
Download source - 16 Kb


  • Detected Memory Leak, To improve this problem...

    Posted by Legacy on 11/01/2003 08:00am

    Originally posted by: Jung Hyun-Seung

    void Close()
    if(m_nRowsetType == 2)
    ((CCommand<TAccessor, TRowset>*)m_pSet)->ReleaseCommand(); // Add this Line
    m_bIsOpen = false;
    m_bEOF = false;
    m_bBOF = false;


    Posted by Legacy on 08/01/2002 07:00am

    Originally posted by: Sanjay

    I wanted to connect to remote oracle database thru VB 6 (ADO) without installing the oracle client software on my machine. Is it possible ?

    thnx in advance


    • hi

      Posted by dhananjaypadalkar on 01/24/2009 12:46pm

      i had same requirement , i want connect client with ip address to server just like with "type 4" drivers used in java

  • Can't write...

    Posted by Legacy on 03/05/2002 08:00am

    Originally posted by: Stanislav P.

    I can't write to Interbase 5.0 or 6.0 table thru ODBC provider...
    Reading is OK.

  • Version for VS.Net

    Posted by Legacy on 02/24/2002 08:00am

    Originally posted by: Alex Mitchell

    I am interested in a solution foe VS.Net
    The following does not compile:

    CSypODLRecordBase<CAccessor<CSalesManTableAccessor> > m_Rs;

  • What a Cool Way!!!

    Posted by Legacy on 12/04/2001 08:00am

    Originally posted by: Chandresh Patel

    POWERWAY!!! I am very happy to use this code and now my all problem with ado and bind with grid is all clear

  • Thanks

    Posted by Legacy on 12/04/2001 08:00am

    Originally posted by: Bug Alert

    Maybe someday i will figure it out wats it about...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date