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.
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 = NothingInstall the appropriate Access Database Engine provider on the IIS server, and keep the database file outside publicly downloadable paths wherever possible.
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.
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.
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 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.
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.
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.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.