Microsoft ActiveX Data ObjectsMicrosoft ActiveX Data Objects*
*Contents  *Index  *Topic Contents

ADO Overview

ActiveX™ Data Objects (ADO) enables you to write an application to access and manipulate data in a database server through an OLE DB provider. ADO’s primary benefits are high speed, ease of use, low memory overhead, and a small disk footprint.

ADO Features

ADO supports key features for building client/server and web-based applications, including the following:

Note While ADO supports these features, the underlying providers and drivers called by ADO may not. Check the topic, Using OLE DB Providers with ADO as well as the documentation for the underlying providers and drivers to determine what functionality they support. Unless otherwise noted in the language reference topics, all of the ADO 1.5 Objects, Methods, and Properties described in this document are available when used with the Microsoft OLE DB Provider for ODBC and Microsoft SQL Server version 6.5.

Remote Data Service

ADO’s Remote Data Service (RDS) allows data remoting, by which you can move data from a server to a client application or Web page, manipulate the data on the client, and return updates to the server in a single round trip. Previously released as Advanced Data Connector 1.0, RDS has been combined with the ADO programming model to simplify client-side data remoting. For more information, see the Remote Data Service documentation.

Installing ADO

As part of the Microsoft Data Access Components, ADO and RDS are automatically installed and registered by a host product, such as Microsoft Internet Information Server. The host product setup program may require that you specifically request the Microsoft Data Access COmponents in order to have ADO and RDS installed.

Programming with ADO

ADO is a dual-interface COM type library. The filename is msado15.dll. The program ID (ProgID) is “ADODB.” In 2 and 3 tier database applications, ADO code that is to execute on the client uses the ProgID “ADOR” instead.

To use ADO with Microsoft Visual Basic or Microsoft Office, you also need to establish a reference to the ADO type library. Select References from the Project menu, check the box for “Microsoft ActiveX Data Objects 1.5 Library,” and then click “OK.” ADO objects, methods, and properties will then be accessible through the VBA Object Browser and the IDE Editor.

To use ADO with Microsoft Visual J++, you also need to create a set of class files using the Java Type Library Wizard. Select the Java Type Library Wizard from the Tools menu, check the box for “Microsoft ActiveX Data Objects 1.5 Library,” and then click “OK.” The wizard will then create the necessary Java class files for ADO.

For some programming languages, you also need to reference (using the #include statement) one or more additional files in your source code, as shown in the table below:
For C++For VBScriptFor JScript
adoint.hadovbs.incadojavas.inc
adoid.h

Threading

The ADO library is free-threaded, but listed in the Windows Registry as apartment model. The thread safety of ADO depends on the underlying provider and data source. For example, the Microsoft OLE DB Provider for ODBC is free-threaded, but not all ODBC drivers are. You should use ADO as apartment model unless you can verify that all of the underlying components can be used free-threaded.

ADO Objects

Although ADO objects are creatable outside the scope of a hierarchy, the objects exist within hierarchical relationships, as shown in the ADO Object Model.

There are 7 objects in the ADO object model:

Command - Maintains information about a command, such as a query string, parameter definitions, etc. You can execute a command string on a Connecton object or a query string as part of opening a Recordset object, without defining a Command object. The Command object is useful where you want to define query parameters, or execute a stored procedure that returns output parameters.

Connection - Maintains connection information with the data provider.

Error - Contains extended error information about an error condition raised by the provider. Since a single statement can generate two or more errors, the Errors collection can contain more than one Error object at a time, all of which result from the same incident.

Field - Contains information about a single column of data within a Recordset. The Recordset object features a Fields collection to contain all of its Field objects.

Parameter - A single parameter for a parameterized Command. The Command object features a Parameters collection to contain all of its Parameter objects.

Property - A provider-defined characteristic of an ADO object.

Recordset - A set of records returned from a query, and a cursor into those records. You can open a Recordset (i.e., execute a query) without explicitly opening a Connection object. However, if you do first create a Connection object, you can open multiple Recordset objects on the same connection.

Each of these objects features a set of properties and methods with which you can manipulate the object and its contents.

Dynamic Properties Collections

The Connection, Command, and Recordset objects each supports a Properties collection. The properties collection contains any dynamic (or “provider-specific”) properties exposed through ADO by the provider. You use the collection and the Item method to reference the property by it’s name or by it’s ordinal position in the collection, as shown:

Command.Properties.Item(0)
Command.Properties.Item(“Name”)

Since the Item method is a default method on an ADO collection, you can omit it:

Command.Properties(0)
Command.Properties(“Name”)

Further, the Properties collection itself is the default collection for the Connection, Command, andRecordset objects, so you can omit it as well:

Command(0)
Command(“Name”)

All of these syntax forms are identical. Which one you choose depends on your coding style preference.

Working with Data

In ADO, the Recordset object is the main interface to data. While the other objects are useful for managing connections, collecting error information, persisting queries, etc., most of your code’s interaction with ADO will involve one or more Recordset objects.

Here is the minimum code (using Microsoft® Visual Basic® Scripting Edition) needed to generate a Recordset from an ODBC data source:

set rstMain = CreateObject("ADODB.Recordset")
rstMain.Open "SELECT * FROM authors", _
"DATABASE=pubs;UID=sa;PWD=;DSN=Publishers"

This generates a forward-only, read-only Recordset object. With a few modifications, you can obtain a more functional Recordset:

set rstMain = CreateObject("ADODB.Recordset")
rstMain.Open "SELECT * FROM authors", _
"DATABASE=pubs;UID=sa;PWD=;DSN=Publishers",
adOpenKeyset, adLockBatchOptimistic

This creates a fully scrollable and batch-updatable Recordset.

Note In order to reference ADO constants by name (instead of by value) when coding in a scripting language, as shown in these code examples, you must include the appropriate header file. For Microsoft Visual Basic Scripting Edition, include the file adovbs.inc in your code. For Microsoft JScript™, include the file adojavas.inc in your code. You should always refer to constants by name rather than by value since the values may change from one version to the next.

For the latest information on ADO, visit the Microsoft ADO web page.


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.