How to connect to a MS Access database from an ASP Script

Please use the following sample code to connect to a MS Access .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
%>

  • 2 Users Found This Useful
Was this answer helpful?

Related Articles

I am receiving System.Security.SecurityException or That assembly does not allow partially trusted callers.

When running your application you may see: That assembly does not allow...

How can I redirect one URL to another on ASP .NET?

Our ASP plans have the following installed:...

Cryptography with ASP .NET

A customer received the following error when attempting to create a RSACryptoServiceProvider from...

I am getting a 404 error on the secondary pages of my MVC application. Why?

To resolve the 404 error issues on secondary pages of a ASP .NET MVC applications, you will need...

My site is showing the following error: HTTP Error 503. The service is unavailable.

The error HTTP Error 503. The service is unavailable. generally means that your application pool...