In computing, Microsoft's ActiveX Data Objects (ADO) comprises a set of Component Object Model (COM) objects for accessing data sources. A part of MDAC (Microsoft Data Access Components), it provides a middleware layer between programming languages and OLE DB (a means of accessing data stores, whether databases or not, in a uniform manner). ADO allows a developer to write programs that access data without knowing how the database is implemented; developers must be aware of the database for connection only. No knowledge of SQL is required to access a database when using ADO, although one can use ADO to execute SQL commands directly (with the disadvantage of introducing a dependency upon the type of database used).
Microsoft introduced ADO in October 1996, positioning the software as a successor to Microsoft's earlier object layers for accessing data sources, including RDO (Remote Data Objects) and DAO (Data Access Objects).
ADO is made up of four collections and twelve objects.
ADO collections
Fields This collection contains a set of Field objects. The Collection can be used in either a Recordset object or in a Record object. In a Recordset object, each of the Field objects that make up the Fields collection corresponds to a column in that Record set object. In a Record object, a Field can be an absolute or relative URL that points into a tree-structured namespace (used for semi-structured data providers like the Microsoft OLE DB Provider for Internet Publishing) or as a reference to the default Stream object associated with that Record object. Properties An object can have more than one Property object, which are contained in the object's Properties collection. Parameters A Command object can have several Parameter commands to change its predefined behaviour, and each of the Parameter objects are contained in the Command object's Parameters collection Errors All provider-created errors are passed to a collection of Error objects, while the Errors collection itself is contained in a Connection object. When an ADO operation creates an error, the collection is cleared and a new group of Error objects is created in the collection.ADO objects
Connection The connection object is ADO's connection to a data store via OLE DB. The connection object stores information about the session and provides methods of connecting to the data store. As some data stores have different methods of establishing a connection, some methods may not be supported in the connection object for particular OLE DB provider. A connection object connects to the data store using its 'Open' method with a connection string which specifies the connection as a list of key value pairs (for example: "Provider='SQLOLEDB';Data Source='TheSqlServer'; Initial Catalog='Northwind';Integrated Security='SSPI';"). The start of this connection string must identify the type of data store connection that the connection object requires:- an OLE DB provider (for example SQLOLEDB), using the syntax "provider=";
- a file name, using the syntax "file name=";
- a remote provider and server (see RDS), using the syntax "Remote provider=" and "Remote server="; or
- an absolute URL, using the syntax "URL="
Basic usage
Some basic steps are required in order to be able to access and manipulate data using ADO :
- Create a connection object to connect to the database.
- Create a recordset object in order to receive data in.
- Open the connection
- Populate the recordset by opening it and passing the desired table name or SQL statement as a parameter to open function.
- Do all the desired searching/processing on the fetched data.
- Commit the changes you made to the data (if any) by using Update or UpdateBatch methods.
- Close the recordset
- Close the connection
ASP example
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 = nothingThis 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)Software support
ADO is supported in any development language that supports binding to binary COM interfaces. These languages include ASP, Delphi, PowerBuilder, and Visual Basic for Applications (VBA). ADO support has now been added to dBase Plus 8 (With ADO)
Legacy
ADO.NET has replaced ADO in the same way that C#/.NET replaced C/Win32 as the primary mode for targeting Windows application development. ADO.NET follows the same design pattern as ADO, enabling an ADO developer an easy path forward when moving to the .NET framework.
See also
- ADO.NET
- Comparison of ADO and ADO.NET
- MSDAIPP
External links
- Microsoft ADO page
- Database connection strings Archived January 26, 2021, at the Wayback Machine
- DevGuru ADO Quick Reference