Server Pages (ASP)
Server Pages (ASP)
Session 76
Connecting to data with ASP
Accessing a Database from an ASP Page
ADO can be used to access databases from your web
pages
What is ADO?
ADO is a Microsoft technology
ADO stands for ActiveX Data Objects
ADO is a Microsoft Active-X component
ADO is automatically installed with Microsoft IIS
ADO is a programming interface to access data in a
database
To access a database
Steps
Create an ADO connection to a database
Open the database connection
Create an ADO recordset
Open the recordset
Extract the data you need from the recordset
Close the recordset
Close the connection
ADO - Objects
ADO consists of four objects with their corresponding
properties and methods.
1. Connection
a. Methods
i. Open
ii. Execute
iii. Close
ADO -Objects
2. Recordset
a. Properties
i. bof
ii. eof
b. Methods
i. Open
ii. Movefirst
iii. Movenext
iv. Close
ADO -Objects
3. Command
a. Properties
i. Commandtext
b. Method
i. Execute
4. Error
a. Properties
i. count
ii. item
ADO - Connection
There are 3 types of connections
1. ODBC DSN
2. ODBC DSN-less
3. OLE DB
ODBC DSN
ODBC(Open Database Connectivity) is an open
standard developed in 1990's.
It provides simple programming interface to relational
databases.
DSN(Data Source Name) is a saved entry in Windows
ODBC applet
which defines all connection information
and provides a simple name to handle connectivity.
Syntax of connection through ODBC DSN
conn.open "DSN=DSNname;" & "Uid=Username;"
& "Pwd=Password;"
ODBC DSN-less
This connection also uses ODBC, but does not use a
saved DSN entry.
Advantages of using this type of connection
saves a call to the Windows Registry because of the
quickness of its service
Avoid having to have the DSN created on the web
server.
More portable
More flexible and can pass database names as
variables.
ODBC DSN-less
The syntax is
Dim Conn
Set Conn =
Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=msdaora;"
"Data Source=PSTDB;" & "User Id=username;" &
"Password=password;"
Retrieving Data from the Table
Student table