ActiveX Data Objects

This is an old revision of this page, as edited by Cpc464 (talk | contribs) at 10:58, 22 June 2006 (Lots of changes). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Microsoft ActiveX Data Objects (ADO) is a set of Component Object Model objects for accessing data sources. It provides a layer between programming languages and OLE DB (a means of accessing data stores, whether they be databases or otherwise, in a uniform manner), which allows a developer to write programs which access data, without knowing how the database is implemented. You must be aware of your database for connection only. No knowledge of SQL is required to access a database when using ADO, although one can use ADO to execute arbitrary SQL commands. The disadvantage of this is that this introduces a dependency upon the type of database used.

It is positioned as a successor to Microsoft's earlier object layers for accessing data sources, including RDO (Remote Data Objects) and DAO (Data Access Objects). ADO was introduced by Microsoft in the winter of 1996.

ADO consists of several top-level objects:

  • Connection (represents the connection to the database)
  • Recordset (represents a set of database records)
  • Command (represents a SQL command)
  • Record (represents a set of data, typically from a source other than a database)
  • Stream (represents a stream of data, as from a text file or web page)
  • Error (stores errors)
  • Field (represents a database field)
  • Parameter (represents a SQL parameter)
  • Property (stores information about objects)

The ADO components are usually used in conjunction with a high-level language such as VBScript in an ASP environment or Visual Basic. However, languages such as Delphi and C++ Builder, development environments from Microsoft rival Borland Software Corporation, also allow the use of ADO to access various databases.

In the newer programming framework of .NET, Microsoft also presented an upgraded version of ADO called ADO.NET. Its object structure is quite different from that of traditional ADO. Traditional ADO is still very popular, and is often perceived as being more mature.

Here is an ASP example using ADO to select the "Name" field, from a table called "Phonebook", where a "PhoneNumber" was equal to "555-5555".

dim myconnection, myrecordset, name
set myconnection = server.createobject("ADODB.Connection")
set myrecordset = server.createobject("ADODB.Recordset")

myconnection.open mydatasource
myrecordset.open "Phonebook", myconnection
myrecordset.find "PhoneNumber = '555-5555'"
name = myrecordset.fields.item("Name")
myrecordset.close

set myrecordset = nothing
set myconnection = nothing

This is equivalent to the following ASP code, which uses plain SQL instead of the functionality of the Recordset object:

dim myconnection, myrecordset, name
set myconnection = server.createobject("ADODB.connection")
myconnection.open mydatasource
set myrecordset = myconnection.execute("SELECT Name FROM Phonebook WHERE PhoneNumber = '555-5555'")
name = myrecordset(0) 
myrecordset.close

set myrecordset = nothing
set myconnection = nothing