Introduction to ADO

Wednesday, September 19, 2012

tags ADO

Microsoft's ActiveX Data Objects (ADO) was introduced in 1996 by Microsoft. It is a set of Component Object Model (COM) objects for accessing data sources. It provides a middleware layer between programming languages and OLE DB. ADO allows a developer to write programs that access data without knowing how the database is implemented. While no knowledge of SQL is required to access a database when using ADO, it is common for to directly execute SQL commands. In the case of web development, simply put, ADO can be used to access databases from your web pages.


Before you continue to learn more about ADO, you should have a basic understanding of HTML, ASP, and SQL.

How to Implement ADO

In the next upcoming tutorials, we will take a deeper look into how ADO can be incorporated into your ASP web applications to access a data source. However, to simplify the process, the following high level steps are executed:

  1. Create an ADO connection to a database
  2. Create an ADO recordset to receive data
  3. Open the database connection
  4. Open the recordset
  5. Extract the data you need from the recordset
  6. Close the recordset
  7. Close the connection


In this example, we are going to connect to a table in a MySQL database called "Employees". We will run a SQL Select Query and capture the results in a recordset. Finally, extract the information from the record set and display the results in a table.

<!DOCTYPE html>
    <title>My Page</title>

Dim connection, recordset, datasource, sql
Set connection=Server.CreateObject("ADODB.Connection")
Set recordset = Server.CreateObject("ADODB.recordset")
datasource = "Driver={MySQL ODBC 3.51 Driver};SERVER=db-hostname;DATABASE=db-name;UID=userID;PWD=password"
sql = "SELECT empName, empTitle FROM employees"
connection.Open datasource
recordset.Open sql, connection
<table style="width:500px;">
  <%for each x in recordset.Fields
        Response.Write("<th>" & & "</th>")
  <%do until recordset.EOF%>
    <%for each x in recordset.Fields%>
  Set oRS=nothing
  Set oConn=nothing


In the previous example, you could easily connect to a different data source simply by changing the value of the 'datasource' value. Microsoft's philosophy behind ADO, as well as a series of related technologies, is Universal Data Access (UDA). UDA is not a product, but rather a strategy for simplifying the complexity of data access. UDA is meant to eliminate the need to convert existing data from one proprietary format to another.

Did you find the page informational and useful? Share it using one of your favorite social sites.

Recommended Books & Training Resources

ADO Programming for Dummies ADO Programmers Reference ADO: ActiveX Data Objects