Connecting to an Access Database Using ASP/ADO
This example describes using ASP/ADO to connect to an Access Database.
NOTE: This code requires full trust and will not work on hosting accounts running ASP.Net 2.0/3.0/3.5/4.0.
<%
Dim oConn, oRs
Dim qry, connectstr
Dim db_path
Dim db_dir
db_dir = Server.MapPath("access_db") & "\"
db_path = db_dir & "yourdatabasefile.mdb"
fieldname = "your_field"
tablename = "your_table"
connectstr = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & db_path
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr
qry = "SELECT * FROM " & tablename
Set oRS = oConn.Execute(qry)
if not oRS.EOF then
while not oRS.EOF
response.write ucase(fieldname) & ": " & oRs.Fields(fieldname) & ""
oRS.movenext
wend
oRS.close
end if
Set oRs = nothing
Set oConn = nothing
%>
Dim oConn, oRs
Dim qry, connectstr
Dim db_path
Dim db_dir
db_dir = Server.MapPath("access_db") & "\"
db_path = db_dir & "yourdatabasefile.mdb"
fieldname = "your_field"
tablename = "your_table"
connectstr = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & db_path
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open connectstr
qry = "SELECT * FROM " & tablename
Set oRS = oConn.Execute(qry)
if not oRS.EOF then
while not oRS.EOF
response.write ucase(fieldname) & ": " & oRs.Fields(fieldname) & ""
oRS.movenext
wend
oRS.close
end if
Set oRs = nothing
Set oConn = nothing
%>
NOTE: Web Hosting accounts do not support Access databases. See What type of hosting account do I have? for more information.
Rate This Article:
35 People Found this Helpful
Related Topics:
Related Articles:
What Do I Do When I Receive an Updateable Query Error?
How Many Access Databases Can I Have On My Shared Hosting Account?
Importing Data from MS Access to MS SQL
Managing Your Hosting Account's Databases
Removing Databases from Your Hosting Account
Setting up an Access Database for Your Hosting Account
Connecting to an Access Database Using File DSN and ASP/ADO
How Many Access Databases Can I Have On My Shared Hosting Account?
Importing Data from MS Access to MS SQL
Managing Your Hosting Account's Databases
Removing Databases from Your Hosting Account
Setting up an Access Database for Your Hosting Account
Connecting to an Access Database Using File DSN and ASP/ADO
Have a question about the content of this article?
Sending Message...
0 min expected wait time