Frequently Asked Questions

Help Center Search

Connecting to an Access Database Using File DSN and ASP/ADO

Print this Article
Last Updated: June 20, 2008 3:50 PM

This example describes using File DSN and ASP/ADO to connect to an Access Database.

<%
Dim oConn, oRs
Dim qry, connectstr, sDSNDir
Dim db_name, db_username, db_userpassword
Dim dsn_name

dsn_name = "your_dsn_name"
fieldname = "your_fieldname"
tablename = "your_tablename"

'assumes that _dsn exists in the root
sDSNDir = Server.MapPath("/_dsn")

connectstr = "filedsn=" & sDSNDir & "/" & dsn_name

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

%>