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

  • Lenovo recommends Windows 8 Pro. "I dropped my laptop getting out of the taxi." This probably sounds familiar to most IT professionals. If your employees are traveling, you know their devices are in for a rough go. Whether it's a trip to the conference room or a convention out of town, any time equipment leaves a user's desk it is at risk of being put into harm's way. Stay connected at all times, whether at the office or on the go, with agile, durable, and flexible devices like the Lenovo® …

  • On-demand Event Event Date: September 23, 2015 The cloud is not just about a runtime platform for your projects – now, you can do your development in the cloud, too. Check out this webcast to learn how the cloud improves your development experience and team collaboration. Join Dana Singleterry, Principal Product Manager for Oracle Dev Tools, as he discusses how to simplify every aspect of the development lifecycle, including requirements gathering, version management, code reviews, build automation, and …

Most Popular Programming Stories

More for Developers

RSS Feeds

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