Database Support (ADODB)

ASPPY natively emulates classic ADODB objects (ADODB.Connection, ADODB.Recordset, ADODB.Command). It fully translates VBScript syntax and logic into secure Python database drivers under the hood.

Supported Drivers

ASPPY dynamically parses the ConnectionString and routes connections to standard Python DB-API drivers.

  • SQLite (Default) - Driver={SQLite3 ODBC Driver};Database=test.db
  • Microsoft Access - Requires pyodbc. Provider=Microsoft.ACE.OLEDB.12.0;Data Source=...
  • SQL Server - Requires pyodbc. Provider=SQLOLEDB;Data Source=...
  • MySQL / MariaDB - Requires mysql-connector-python. Driver={MySQL ODBC 8.0 Driver};...
  • PostgreSQL - Requires psycopg2. Driver={PostgreSQL Unicode};...

ADODB.Connection

Opens a connection to the database and executes queries.

<%
Dim conn, rs
Set conn = Server.CreateObject("ADODB.Connection")

' Connect to an SQLite database (auto-created if it doesn't exist)
conn.Open "Provider=SQLite;Data Source=" & Server.MapPath("/data/app.db")

' Execute raw SQL
conn.Execute "CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)"
conn.Execute "INSERT INTO users (name) VALUES ('John Doe')"

' Retrieve a Recordset
Set rs = conn.Execute("SELECT * FROM users")

Do While Not rs.EOF
    Response.Write "User ID: " & rs("id").Value & " - Name: " & rs("name").Value & "<br>"
    rs.MoveNext
Loop

rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
%>

ADODB.Recordset

Standard recordset iteration and updating.

Method/PropertyDescription
Open(sql, connection)Executes the query and opens the recordset.
EOF / BOFChecks if the cursor has reached the end or beginning of the set.
MoveNext / MoveFirstNavigates the dataset.
Fields(name).ValueRetrieves the column value for the current row.
AddNew() / Update()Inserts a new row or commits changes to the current row.
Delete()Deletes the current row.
Updatable Recordsets Example
<%
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
' Open a dynamic/updatable recordset
rs.Open "SELECT * FROM users", conn, 1, 3 ' adOpenKeyset, adLockOptimistic

rs.AddNew
rs("name") = "Jane Smith"
rs.Update

rs.Close
%>

ADODB.Command

Prevents SQL injection by using parameters.

<%
Dim cmd, rsParam
Set cmd = Server.CreateObject("ADODB.Command")
cmd.ActiveConnection = conn
cmd.CommandText = "SELECT * FROM users WHERE name = ?"

' Add a parameter
cmd.Parameters.Append cmd.CreateParameter("name", 200, 1, 50, "Jane Smith") ' adVarChar=200, adParamInput=1

Set rsParam = cmd.Execute()
If Not rsParam.EOF Then
    Response.Write "Found: " & rsParam("name")
End If
rsParam.Close
%>
ASPPY Security Bonus: ASPPY provides an extension allowing you to append AutoEscapeSQL=1; to your ADODB connection strings to attempt automatic SQL injection sanitization on legacy queries.