Speed up Recordset creation with the CommandType property

Speed up Recordset creation with the CommandType property

If you want to create an ADO Command using VB code, remember to always set the CommandType property to the appropriate adCmdxxxx constant value. If you don’t this, will be used the default adCmdUnknow value, and the Data Provider must test the CommandText property to determine if it is a stored procedure, a table name, or a SQL statement before executing the query. This behaviour can cause a significant reduction in performance, because multiple trips to the database server are required.

You should apply this tip to all ADO methods that expect a CommandType argument, such the Open method of the Recordset object:

Dim rs As New ADODB.Recordset' CN is an open and valid ADO connection objectrs.Open "Authors", cn, adOpenStatic, adLockReadOnly, adCmdTable

See also  11 Effective Keyword Research Tools and Techniques

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