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

  • As the mobile enterprise marketplace expands and customer needs grow more diverse, Samsung recognizes that solution partners and developers play an essential role by continually innovating to meet their customers' needs. Samsung works to provide these developers and partners with the latest tools and resources needed to create these solutions. Read this program guide to learn how the Samsung Enterprise Alliance Program provides partners and developers with Samsung enterprise software development kits (SDKs) …

  • Power and Automation Equipment makers face constrained CAPEX, equipment interoperability issues, and process inefficiencies. However, they can take advantage of secure Internet of Things (IoT) intelligent devices and systems to make better business decisions around asset utilization and performance, while simultaneously optimizing equipment interoperability and services efficiency. Watch this brief video to see how you can unlock the full potential of your assets and value chain.

Most Popular Programming Stories

More for Developers

RSS Feeds

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