Database Programming ATL

How to use ATL OLE/DB code with an ADO connection


Environment: VC++ 6, Windows 2000

This article is for Visual C++ -- OLE/DB programmers that are using ATL but must interact with components or code (from VB or even Visual C++) using ADO. Some time ago was really a problem for me to use such components without changing my code that was using ATL OLE/DB style for accessing a database.

The key code is where the ADO.s Connection is used to get a CSession:

.  .  .

   HRESULT hr;


         _T("ADODB.Connection"), e))
             throw e;

      CString strConnection;

      m_pADOconnection->Open(strConnection,"admin","", 0);

      if(FAILED(hr)) return hr;
      if(FAILED(hr)) return hr;

      hr=pSession->QueryInterface( IID_IOpenRowset,
      if(FAILED(hr)) return hr;

   . . .


Download source - 35 Kb


  • How to query.

    Posted by Legacy on 04/10/2003 12:00am

    Originally posted by: csjung

    How can i insert data and query using this code?
    eg) Inset Into mlist VALUES(~~~)
    : to insert data.
    Select * from mlist where FirstName = 'name1'
    : to query record.

    Thanks in advance.

  • how to use SQL Server for this example?

    Posted by Legacy on 12/21/2001 12:00am

    Originally posted by: James

    Thanks, I have a SQL Server DB in another computer,
    its Data Source name is: DBTest

    how can I connect to it with your sample?


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

Top White Papers and Webcasts

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

Most Popular Programming Stories

More for Developers

RSS Feeds

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