devxlogo

Reuse a Recordset’s Connection

Reuse a Recordset’s Connection

ADO lets you create a Recordset without creating an explicit Connection object, using the following syntax:

Dim rs As New ADODB.Recordsetrs.Open "Authors", "DSN=Pubs"

If you later want to create another Recordset, but you (correctly) don’t want to create another database connection, you can reuse the implicit Connection object that ADO has created for the first Recordset, as in:

Dim rs2 As New ADODB.RecordsetSet rs2.ActiveConnection = rs.ActiveConnectionrs2.Open "Publishers"

or, more simply, with

Dim rs2 As New ADODB.Recordsetrs2.Open "Publishers", rs.ActiveConnection

See also  The Importance of Red Teaming in Modern Cyber Defense Strategies
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist