Connecting Classic ASP to Access with ADO

Use this example to see the core idea, then work through the complete steps below. Code snippets are Classic ASP / VBScript or SQL Server T-SQL as labelled, not PHP.

Open an Access connection

VBScript example

Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
        Server.MapPath("db/months.mdb")
' Run a query here, then close the connection.
cn.Close
Set cn = Nothing

Install the appropriate Access Database Engine provider on the IIS server, and keep the database file outside publicly downloadable paths wherever possible.

Important: Check provider bitness, file permissions and path. A shared Access file is usually unsuitable for high-concurrency public web applications.
On this page — Show page sectionsHide page sections

This tutorial preserves the original Classic ASP + Microsoft Access ADO example because it is still useful when maintaining older sites. For new server-side applications, prefer a server database such as SQL Server rather than designing a new web application around an Access .mdb/.accdb file.

Legacy/server-support note: Microsoft states that the Access Database Engine is not intended as a replacement for Jet in server-side applications. The ACE connection below is therefore shown as a legacy-compatibility example for environments where the provider is already installed and supported by the application owner. Verify provider availability, licensing/support and process bitness before relying on it.

Create and open an ADO Connection

Set objconn = Server.CreateObject("ADODB.Connection")
objconn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & _
Server.MapPath("db/months.mdb")
objconn.Open

Server.MapPath() converts the site-relative database path into a physical server path. Keep writable Access database files outside publicly downloadable folders and grant only the IIS identity permissions the application actually needs.

Create a Recordset object

Set objRs = Server.CreateObject("ADODB.Recordset")

A Recordset represents the rows returned by a table or query. For read-only listing pages, prefer the simplest forward-only/read-only behavior that meets the page's needs.

Recordset.Open syntax

Recordset.Open Source, Connection, cursortype, locktype, commandtype

The Source may be a table, SQL statement or command; the selected cursor and lock types determine which navigation and update features are available.

Before connecting: IIS and the provider

Classic ASP runs on IIS. Check whether the installed ACE provider matches the application pool bitness. Verify read/write permissions, database path, and whether the database is an .mdb or .accdb file. Do not store a downloadable database in a public web directory.

Close objects after use

Open one connection, perform your queries, close the Recordset first, and then close the connection. For SQL Server applications, use the separate SQL Server connection example.

Frequently asked questions

Do these examples require Classic ASP on IIS?
Yes. The server-side code uses VBScript and ADO components from Classic ASP; the .php file here is the Plus2Net tutorial wrapper.
Can I pass form input directly into SQL strings?
No. Validate it and bind it through ADO parameters rather than concatenating it into SQL text.
What should I do if no records match?
Check EOF before accessing fields and show a clear empty-result message.

Back to top ↑


ASP Home






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer