DEV Community

Connect MS Access to SQL Server using ADO

The code provides a set of procedures for working with a database using ADODB connections and recordsets. The procedures include opening a connection, opening a recordset to read or update, closing a recordset, and closing a connection. The connection string is defined using constants for the server name, database name, user ID, and password. The OpenConnection procedure sets the connection timeout and connection string, and then opens the connection. The OpenRecordsetToRead and OpenRecordsetToUpdate procedures set the cursor location, cursor type, and lock type, and then open the recordset. The CloseRecordset and CloseConnection procedures check if the recordset or connection is open, close it, and set it to nothing. The GetRecordset procedure demonstrates how to use these procedures to select data from a table and print the results. The ExecuteSQL procedure demonstrates how to execute an insert, update, or delete statement, and includes error handling with transactions. The error handling procedures close the recordset and connection, and print the error number and description.
favicon
dev.to
dev.to
Create attached notes ...