ASP Database Objects

For the purposes of this tutorial, there are three main tools used in order to allow you to connect to a database. This code assumes the use of Microsoft Access 2000 as the database we are to connect to.

Find the path to the database file:


'Declare Variables
Dim dcnDB	'As ADODB.Connection
Dim rsDB	'As ADODB.Recordset
Dim sqlQuery	'As String

'Find path of database file
filePath = Server.MapPath("ADVISOR.MDB")

Open the database connection using the Microsoft Jet Database Engine:


'Open Database Connection
Set dcnDB = Server.CreateObject("ADODB.Connection")
dcnDB.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&filePath
dcnDB.Open

'dcnDB.Open "DBName" - This is for an ODBC Datasource (if set up) or
'                      use the below code for opening a Access 2000 DB

Query the database and create a recordset


'Query and create recordset
sqlQuery = "SELECT * FROM Students ORDER BY LastName,FirstName"
Set rsDB = Server.CreateObject("ADODB.Recordset")
Set rsDB = dcnDB.Execute(sqlQuery)



End of section