How to connect to MS Access Database Using ASP

How to connect to MS Access Database Using ASP
This tutorial documents code for connecting to a MS Access Database using the DSN-Less approach. With DNS-Less approach all you have to do in your code is define the location where your database resides.

Content:

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

%>



To contact the author please click here



More Tutorials from this author can be found at http://www.nabeelakhtar.net

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top