Connect to an Access Database using OLE DB

The preferred way to connect to a database is using OLE DB , in this example we will show how to do just this using our example Access database .

You can download this database here

Script :

<%
'ADO variables
Dim adOpenForwardOnly , adLockReadOnly , adCmdTable
adOpenForwardOnly = 0
adLockReadOnly = 1
adCmdTable = 2
'object variables
Dim objConn , objRS
'create instance of Connection and REcordset objects
Set objConn = Server.CreateObject("ADODB.Connection")
Set objRS = Server.CreateObject("ADODB.Recordset")
'open our example database
objConn.Open "Provider = Microsoft.Jet.OLEDB.4.0;" & _
"Data Source = D:\examples\asp\example.mdb"
'open the tblexample table
objRS.Open "tblexample" , objConn , adOpenForwardOnly , adLockReadOnly , adCmdTable
'display the data in the database , looping through all records
While Not objRS.EOF
response.Write objRS.Fields("id") & "&nbsp"
Response.Write objRS.Fields("link") & "&nbsp"
Response.Write objRS.Fields("description") & "&nbsp"
Response.Write "<p>"
objRS.MoveNext
Wend
'close the recordset
objRS.Close
'destroy our objects
Set objRS = Nothing
Set objConn = nothing
%>

Note :

You will have to change the datasource to the exact path to your database in this example "Data Source = D:\examples\asp\example.mdb"

Sponsors