Creating a Database Connection Using ASP and ActiveX Data
Objects (ADO)
In this tutorial, we'll learn how to create a basic database
connection that will allow you to display values currently stored in
a database. Again, this example is based upon the assumption that
you are using Microsoft Access as your database and Microsoft
FrontPage as your web development program.
While Active Server Pages (ASP) represents the computer code that
we will use to access our database, ActiveX Data Objects (ADO) is
something completely different. It is a set of objects created to
simplify the process of connecting to data sources. It is NOT
restricted to ASP. It is available to programmers using Visual C++,
Java and Visual Basic. It is built into Microsoft Internet
Information Server (IIS) so it is also available to any Microsoft
hosted website.
Essentially ADO is a set of data access
objects that sits between your ASP code and your database to
simplify your data access.
For this example, we have created a database called
FPTutorials.mdb and created a connection called FPTutorials. The
table we will be viewing is called tAddRecordsTutorial.
In order to view database table records, you need to do several
things.
- Declare the variables that you will be sending to the database
- Open a connection with your database
- Display the data
- Close the database connection
Tell the script that you will declare all variables by using
Option Explicit and then declare your variables.
<%option explicit%>
Begin your web page by placing the html, head and body tags.
<HTML>
<HEAD>
<TITLE>Basic Database Connections</TITLE>
</HEAD>
<BODY>
Assign form values to variables, one for your database connection
(objConn) and one for your recordset (objRS).
<%
Dim objConn, objRS
Open your database Connection. Change the Server.MapPath to match
YOUR database. If you use the default fpdb directory that FrontPage
recommends, then you will need to change just the name of the
database connection.
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _