How to connect to MS Access Database Using ASP

This tutorial will show you how to connect to a MS Access database using the DSN-less approach.
Remember, your database can reside anywhere in your computer. If you are not sharing your database it is advisable not to keep your database under the "wwwroot" directory.

Assumptions:

Database is password protected

Running IIS



Just copy and paste the following code in your ASP file and read the comments to modify settings according to your needs: (Text in grey are comments)







<%

'Start the ASP Tag

Set conn = server.createobject("adodb.connection")



'Define the location of your database and your Password

conn.connectionstring = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=c:\dir\database.mdb;pwd=Your_Password"



'Open Connection

conn.Open





Set rs=Server.CreateObject("ADODB.recordset")



'Enter your SELECT Statement

rs.open "Select col1,col2 from table_name", conn

do until rs.EOF



'Output to browser

response.write ("Col1 and Col2 Values" & rs("col1") & rs("col2") &"<BR>")



'Move to the Next Record in the database

rs.movenext

loop

rs.close



'Close connection

conn.close

%>


Written by