Runoob Tutorial ArchiveEnglish

ADO database connection

ADO database connection


Before accessing data from a webpage, you must first 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. DSN-less connections can be used for any Microsoft Access database on your site.

Assuming you have a database named "northwind.mdb" 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 example above, you must specify the Microsoft Access database driver (Provider) and the physical path of this database on the computer.


Create an ODBC database connection

Assuming 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"

%>

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


ODBC connection to MS Access database

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

  1. Open theODBCicon in the Control Panel
  2. Select SystemODBC Tab
  3. Click theAddbutton in the ODBC tab
  4. SelectDriver to Microsoft Access, then clickFinishButton
  5. Click the "Select" button in the next window to locate the database
  6. Assign a data source name to this database (DataSourceName, DSN)
  7. Click "OK"

Note: This configuration must be completed on the computer where your website is located. If you are running PWS or IIS on your own computer, this architecture can run, but if your website is on a remote server, you must have physical access to this server or ask your web host provider to do this 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.