Connect to a MS Access Database from an ASP Script

Posted by: admin  :  Category: Codes & Scripts, Windows Server Hosting

If you will be using an existing Microsoft Office Access database as storage for your website or web application, you may use the following code to connect with your .mdb file:

<%
Dim ConnectionString
ConnectionString = “DRIVER={Microsoft Access Driver (*.mdb)};” &_
“DBQ=C:\path\to\file.mdb;DefaultDir=;UID=;PWD=;”

Dim Connection
Set Connection = Server.CreateObject(“ADODB.Connection”)

Connection.ConnectionTimeout = 30
Connection.CommandTimeout = 80
Connection.Open ConnectionString
%>

 

C:\path\to\file.mdb is where you’ve uploaded your mdb file and almost always starts off with C:\HostingSpaces\USERNAME where USERNAME is your username.

While the above works for many of our older servers. The following works on our newer servers. You’ll need to make sure that your application is running in a Dedicated App Pool (check box under the website inside your control panel) and that MDAC is installed on the server which all of our new servers already have installed (ask our support staff if it doesn’t work).

<%
Dim ConnectionString
ConnectionString = “Provider=Microsoft.Jet.OLEDB.4.0;” &_
“Data Source=C:\path\to\file.mdb;User Id=;Password=;”

Dim Connection
Set Connection = Server.CreateObject(“ADODB.Connection”)

Connection.ConnectionTimeout = 30
Connection.CommandTimeout = 80
Connection.Open ConnectionString
%>

Leave a Reply