ActiveX Data Objects: Difference between revisions

Content deleted Content added
Modified link - old one was invalid
Undid someone's nonsensical contribution
 
(33 intermediate revisions by 26 users not shown)
Line 1:
{{Short description|Component Object Model APIs for accessing data sources}}
{{Use mdy dates|date=January 2019}}
{{Use American English|date=January 2019}}
{{no footnotes|date=February 2013}}
In [[computing]], [[Microsoft]]'s '''ActiveX Data Objects''' ('''ADO''') iscomprises a set of [[Component Object Model]] (COM) [[object (computing)|object]]s for accessing data sources. A part of [[Microsoft Data Access Components|MDAC]] (Microsoft Data Access Components), it provides a [[middleware]] layer between [[programming language]]s and [[OLE DB]] (a means of accessing data stores, whether they be [[database]]s or otherwisenot, in a uniform manner). ADO allows a [[software developer|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. The(with the disadvantage of the latter is that it introducesintroducing a dependency upon the type of database used).
 
Microsoft introduced ADO isin positionedOctober 1996, positioning the software as a successor to Microsoft's earlier object layers for accessing data sources, including [[Remote Data Objects|RDO]] (Remote Data Objects) and [[Jet Data Access Objects|DAO]] (Data Access Objects). ADO was introduced by [[Microsoft]] in October 1996.
 
== Internals ==
 
ADO is made up of four collections and twelve objects.
Line 26 ⟶ 27:
 
; 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 providersprovider. 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=";
Line 38 ⟶ 39:
: The recordset is locked using the adLockOptimistic or adLockPessimistic lock. The data are updated at the data source after the record is changed and the Update method is called.
; Batch
: The recordset is locked using adLockBatchOptimistic and each time Update is called the data are updated in a temporary buffer. Finally, when UpdateBatch is called the data are completely updated back at the data source. This has the advantage of it all being done in memory, and if a problem occurs then UpdateCancel is called and the updates are not sent to the data source.
; Transaction
: If the OLE DB provider allows it, transactions can be used. To start the transaction, the programmer invokes the BeginTrans method and does the required updates. When they are all done, the programmer invokes the CommitTrans method. RollbackTrans can be invoked to cancel any changes made inside the transaction and rollbackroll back the database to the state before the transaction began.
; Record
: This object represents one record in the database and contains a fields collection. A RecordSet consists of a collection of Record objects.
Line 46 ⟶ 47:
: A stream, mainly used in a RecordSet object, is a means of reading and writing a stream of bytes. It is mostly used to save a recordset in an XML format, to send commands to an OLE DB provider as an alternative to the CommandText object and to contain the contents of a binary or text file.
; Parameter
: A parameter is a means of altering the behaviour of a common piece of functionality, for instance a [[stored procedure]] might have different parameters passed to it depending on what needs to be done; these are called parameterised commands.
; Field
: Each Record object contains many fields, and a RecordSet object has a corresponding Field object also. The RecordSet object's Field object corresponds to a column in the database table that it references.
Line 52 ⟶ 53:
: This object is specific to the OLE DB provider and defines an ability that the provider has implemented. A property object can be either a built-in property — it is a well-defined property implemented by ADO already and thus cannot be altered — or can be a dynamic property — defined by the underlying data provider and can be changed
; Error
: When an OLE DB provider error occurs during the use of ADO, an Error object will be created in the Errors collection. Other errors do not go into an Error object, however. For instance, any errors that occur when manipulating data in a RecordSet or Field object are stored in a Status property.SK
 
== Basic usage ==
Line 67 ⟶ 68:
=== ASP example ===
 
Here is an [[Active Server Pages|ASP]] example using ADO to select the "Name" field, from a table called "Phonebook", where a "PhoneNumber" was equal to "555-5555".
 
<sourcesyntaxhighlight lang=asp"vbscript">
dim myconnection, myrecordset, name
set myconnection = server.createobject("ADODB.Connection")
Line 82 ⟶ 83:
set myrecordset = nothing
set myconnection = nothing
</syntaxhighlight>
</source>
 
This is equivalent to the following ASP code, which uses plain SQL instead of the functionality of the Recordset object:
<sourcesyntaxhighlight lang=asp"vbscript">
dim myconnection, myrecordset, name
set myconnection = server.createobject("ADODB.connection")
Line 91 ⟶ 92:
set myrecordset = myconnection.execute("SELECT Name FROM Phonebook WHERE PhoneNumber = '555-5555'")
name = myrecordset(0)
</syntaxhighlight>
</source>
 
==Software support==
ADO is supported in any development language that supports binding to binary COM interfaces. These languages include ASP, [[Embarcadero Delphi |(programming language)|Delphi]], [[PowerBuilder]], and in [[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]]
 
==References==
{{Reflist}}
 
==External links==
* [http://msdn2.microsoft.com/en-us/library/ms805098.aspx Microsoft ADO page]
* [http://www.connectionstrings.com/ Database connection strings] {{Webarchive|url=https://web.archive.org/web/20210126200223/https://www.connectionstrings.com/ |date=January 26, 2021 }}
* [http://www.devguru.com/content/technologies/ado/home.html DevGuru ADO Quick Reference]
 
{{Microsoft APIs}}
{{Authority control}}
 
{{DEFAULTSORT:Activex Data Objects}}
[[Category:Microsoft application programming interfaces]]
[[Category:Data access technologies]]