devxlogo

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

devx-admin

Share the Post: