Click here to Skip to main content
12,508,014 members (54,122 online)
Click here to Skip to main content
Add your own
alternative version

Stats

244.4K views
1.4K downloads
64 bookmarked
Posted

ATL COM and ADO

, 3 Apr 2001
Rate this:
Please Sign up or sign in to vote.
An ATL Component that uses ADO for data.
<!-- Main HTML starts here -->

Introduction

Recently I did a project on online banking at NIIT, Bangalore. The project was coded mostly using VB with a few ATL components thrown in, if only to teach us programming distributed applications. One middle tier component that I programmed was built with ATL and uses ADO to query the backend (SQL Server). Parts of that code appears here.

I assume the reader knows or at least has a fair idea about COM programming using ATL as well as ADO programming with VB.

What is ADO?

ADO stands for ActiveX Data Objects. ADO provides an object-oriented programming interface for accessing a data source using the OLEDB data provider. It is the succesor to DAO and RDO object models and combines the best features DAO and RDO.

Programming OLEDB in C++ is easy. However, for languages like Visual Basic, that do not support pointers and other C++ features, implementing OLEDB is difficult.

This is where ADO really shines. ADO is an high level interface to OLEDB that is based on COM interfaces. Thus any application that supports COM can implement ADO.

ADO Features

  • Access to all types of data - Various data sources include e-mail, text files, RDBMSs, ISAM/VSAM databases and all ODBC data sources.

  • Supports free threading - ADO supports multiple client connections through multiple threads in such a way that these threads do not interfere with each other.

  • Supports asynchronous queries - This basically means that after an SQL query is submitted to the database server, the control returns immediately to the calling application, allowing the user to continue working while the query is being processed. On completion of the query, the results are sent to the client.

  • Supports client-side and server-side cursors - Cursor is a mechanism that allows access and navigation of data in a recordset. They are implemented as client-side or server-side. Traditionally, frequently updated recordsets are implemented as server-side while read-only recordsets are implemented as client-side.

  • Supports disconnected recordsets - After a recordset is returned on execution of a query, it is stored as a client-side cursor and the active connection is closed. After changes have been commited to the recordset, the connection is reestablished and all updates are sent in a batch to the data store. This helps in reducing network traffic to a great extent.

  • Supports Commands as connection methods - An unique feature of ADO is that when a command is executed, a connection is first established internally before that command gets submitted for execution. Compare this to traditional object models like DAO/RDO where a connection has to be established explicitly before a command can be submitted.

ADO Architecture

In the ADO model, we'll be using three main types of objects-

  • Connection
  • Command
  • Recordset

The Connection object sets up a connection to the data source. First, the data source name, its location, user ID, password etc is stored in a ConnectionString object, which is passed to the Connection object.to establish a connection to the data source.

The Command object is used to execute SQL commands, queries and stored procedures.

When a query is executed, it returns results that are stored in the Recordset object. Data in a recordset can be manipulated and then updated to the database.

Using ADO

First, we'll be building an ATL DLL component. This component has a method that takes one input parameter (customer ID in the project) and returns a reference to the corresponding Recordset object to the VB client. The client then displays the data in a form.

To create the DLL, use the ATL COM AppWizard to generate the framework for the application. Name the project FindCust and choose the server type as Dynamic Link Library. Also choose the option to support MFC library.

Insert a New ATL Object of type Simple Object to the project. Use the name Search in the Short Name textbox of the ATL Object Wizard Properties and click OK to add the object.

In classview, right click the interface name and add a method. Name the method SearchCust and type the following in the Parameters textbox :

[in] BSTR bstrcustid,[out,retval] _Recordset **ptr

Click the OK button to add the method.

Since the SearchCust method returns a reference to a Recordset object, we need to import the ADO library. To do this, open the file, StdAfx.h and add the following code :

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Amit Dey
Web Developer
India India
Amit Dey is a freelance programmer from Bangalore,India. Chiefly programming VC++/MFC, ATL/COM and PocketPC and Palm platforms. Apart from programming and CP, he is a self-taught guitar and keyboard player.

He can be contacted at visualcdev@hotmail.com


You may also be interested in...

Pro
Pro

Comments and Discussions

 
AnswerRe: Mempry Leak in ADO? Pin
Anonymous23-Oct-02 15:58
sussAnonymous23-Oct-02 15:58 
GeneralIt Urgent ... Help Me Pin
Anonymous12-Nov-01 19:20
memberAnonymous12-Nov-01 19:20 
GeneralRe: It Urgent ... Help Me Pin
WhyIsThisSo10-Dec-01 12:25
memberWhyIsThisSo10-Dec-01 12:25 
GeneralRe: It Urgent ... Help Me Pin
Anonymous21-Feb-02 12:28
memberAnonymous21-Feb-02 12:28 
GeneralRe: It Urgent ... Help Me Pin
Anonymous15-May-02 11:43
memberAnonymous15-May-02 11:43 
GeneralRe COM & ADO Pin
Harsh Parikh3-Aug-01 10:40
memberHarsh Parikh3-Aug-01 10:40 
GeneralRe: Re COM & ADO Pin
Amit Dey15-Feb-02 8:44
memberAmit Dey15-Feb-02 8:44 
GeneralRe: Re COM & ADO Pin
bibilm25-Sep-02 4:46
memberbibilm25-Sep-02 4:46 
GeneralRe: Re COM & ADO Pin
Amit Dey26-Sep-02 5:58
memberAmit Dey26-Sep-02 5:58 
GeneralRe: Re COM & ADO Pin
bibilm26-Sep-02 6:15
memberbibilm26-Sep-02 6:15 
General2 EXE and 1 COM between Pin
Anonymous4-Jun-01 2:42
memberAnonymous4-Jun-01 2:42 
GeneralRe: 2 EXE and 1 COM between Pin
Kopi11-Jun-01 11:15
memberKopi11-Jun-01 11:15 
Generalvariant_t : the correct way Pin
Amit Dey2-Jun-01 1:38
memberAmit Dey2-Jun-01 1:38 
the correct way to use variant_t( and not _variant_v) in this article is

_variant_t var(DISP_E_PARAMNOTFOUND,VT_ERROR);

Sorry for that small omission.Blush | :O

Hush..Hush.. thought I heard you calling my name now...
Generaldll error Pin
murali31-May-01 6:10
membermurali31-May-01 6:10 
Generalole db in vc6 Pin
Ivgeny Broitman22-May-01 22:09
memberIvgeny Broitman22-May-01 22:09 
Generalerror LNK2001: unresolved external symbol Pin
Anonymous11-May-01 4:22
memberAnonymous11-May-01 4:22 
GeneralRe: error LNK2001: unresolved external symbol Pin
ganeshwalavalkar1-Jun-01 4:13
memberganeshwalavalkar1-Jun-01 4:13 
QuestionHow does the .idl file should be look like? Pin
Itsik saban10-Apr-01 22:16
memberItsik saban10-Apr-01 22:16 
AnswerRe: How does the .idl file should be look like? Pin
Amit Dey10-Apr-01 23:07
memberAmit Dey10-Apr-01 23:07 
AnswerRe: How does the .idl file should be look like? Pin
ganeshwalavalkar1-Jun-01 4:15
memberganeshwalavalkar1-Jun-01 4:15 
GeneralPassing COM as parameter Pin
Anonymous13-Mar-01 2:52
memberAnonymous13-Mar-01 2:52 
GeneralRe: Passing COM as parameter Pin
ganeshwalavalkar1-Jun-01 4:16
memberganeshwalavalkar1-Jun-01 4:16 
GeneralRe: Passing COM as parameter Pin
Anonymous18-Feb-02 21:37
memberAnonymous18-Feb-02 21:37 
GeneralPassing COM as parameter Pin
Anonymous13-Mar-01 2:52
memberAnonymous13-Mar-01 2:52 
GeneralHELP!!! :-( Pin
Carcher27-Feb-01 22:42
memberCarcher27-Feb-01 22:42 
General:mad: :mad: !! INCORRECT AND DANGEROUS !! Pin
Laurent18-Feb-01 7:08
memberLaurent18-Feb-01 7:08 
GeneralRe: :mad: :mad: !! INCORRECT AND DANGEROUS !! Pin
Anonymous14-Mar-01 1:09
memberAnonymous14-Mar-01 1:09 
GeneralRe: :mad: :mad: !! INCORRECT AND DANGEROUS !! Pin
Norm Almond14-Mar-01 1:28
memberNorm Almond14-Mar-01 1:28 
GeneralRe: :mad: :mad: !! INCORRECT AND DANGEROUS !! Pin
Anonymous14-Mar-01 2:19
memberAnonymous14-Mar-01 2:19 
GeneralRe: :mad: :mad: !! INCORRECT AND DANGEROUS !! Pin
Anonymous21-Jun-01 17:17
memberAnonymous21-Jun-01 17:17 
GeneralI need your help Pin
mepark13-Feb-01 17:52
membermepark13-Feb-01 17:52 
GeneralRe: I need your help Pin
Ganesh13-Feb-01 20:22
memberGanesh13-Feb-01 20:22 
Generalhelp me Pin
linghuchong16-Dec-00 16:52
memberlinghuchong16-Dec-00 16:52 
GeneralRe: help me Pin
Anonymous19-Dec-00 19:11
memberAnonymous19-Dec-00 19:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160927.1 | Last Updated 4 Apr 2001
Article Copyright 2000 by Amit Dey
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid