ADO Database Connection


Before accessing data from a web page, you must establish a database connection.


Create a DSN-less Database Connection

The simplest way to connect to a database is to use a DSN-less connection. A DSN-less connection can be used for any Microsoft Access database on your site.

Suppose you have a database named "northwind.mdb" located in the web directory "c:/webdata/", you can use the following ASP code to connect to this database:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
%>

Note that in the above example, you must specify the Microsoft Access database driver (Provider) and the physical path of the database on the computer.


Create an ODBC Database Connection

Suppose you have an ODBC database named "northwind", you can use the following ASP code to connect to this database:

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "northwind"
%>

Through an ODBC connection, you can connect to any database on any computer in your network, as long as the ODBC connection is available.


ODBC Connection to an MS Access Database

Here we explain how to create a connection to an MS Access database:

  1. Open the Control PanelODBCicon
  2. Select SystemODBC tab
  3. Click in the ODBC tabAddbutton
  4. SelectDriver to Microsoft Access, then clickFinishbutton
  5. In the next window, click the "Select" button to locate the database
  6. Give this database a data source name (Data Source Name,DSN)
  7. Click "OK"

Note:This configuration must be done on the computer where your website resides. If you are running PWS or IIS on your own computer, this setup will work, but if your website is on a remote server, you must have physical access to that server, or ask your web hosting provider to do these things for you.


ADO Connection Object

The ADO Connection Object is used to create an open connection to a data source. Through this connection, you can access and operate on this database.

View all methods and properties of this connection object.

Other Extensions