Loading...

Knowledge Base
Categories:

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

Share

Please use the following sample code to connect to a MS Access .mdb file:

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

Dim Connection 
Set Connection = Server.CreateObject("ADODB.Connection") 

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

E:\path\to\file.mdb is where you've uploaded your mdb file and almost always starts off with E:\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=E:\path\to\file.mdb;User Id=;Password=;" 

Dim Connection 
Set Connection = Server.CreateObject("ADODB.Connection") 

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

 

Did you find this article helpful?

 
* Your feedback is too short

Loading...