ASP Access Database Connection

You must have a working knowledge of programming with Active Server Pages (ASP), designing Access databases and HTML to use this information. Web development is not part of free support, but we provide as much information as possible online to assist our customers with Development issues they face.
Learn more about ASP at's ASP Resources page.

For sake of understanding on how you modify the code below for your use, we will use the following:

  • DSN = mydsn
  • Folder database resides in directly off root of website = myfolder
  • Access database name = mydatabase.mdb
  • Table in database = mytable
  • Column in mytable=lastname

First, there are two basic types of connections to an Access database – DSN and DSN-less.


Dim conn Set conn = Server.CreateObject("ADODB.Connection") conn.ConnectionString = "DSN=mydsn" conn.Open


Dim conn Set conn = Server.CreateObject("ADODB.Connection") conn.Open("DRIVER={Microsoft® Access Driver (*.mdb)}; DBQ=" & _ Server.MapPath("myfolder\mydatabase.mdb"))

ASP Source Code

(ASP 3.0 & VBScript) uses the DSN connection noted above.
To use the DSN-less connection noted above, substitute the DSN code with the DSN-less code. The ASP code begins with <% and ends with %>, which is required.
---- code begins under this line of text ----

<%@ Language=VBScript %> <% Dim conn Set conn = Server.CreateObject("ADODB.Connection") conn.ConnectionString = "DSN=mydsn" conn.Open Dim strSQL, rs strSQL = "Select lastname from mytable" set rs = Server.CreateObject("ADODB.Recordset") rs.Open strSQL, conn Response.Write "<h1>Connection Works!</h1>" Response.Write "<h2>Database Records Below</h2>" do while not rs.EOF Response.Write rs("lastname") Response.Write "<BR>" rs.MoveNext loop rs.Close Set rs = Nothing conn.Close Set conn = Nothing %>

---- code ends above this line of text ----

Make I.T. easy for your business with fully managed dedicated hosting from