ONE Active Server Pages Product Home Page Developer Site Version


ADO Command Object Prepared Property

Determines whether or not the provider saves a compiled version of a command before execution. This property is not currently supported on UNIX.

Prepared Property Return Values

Sets or returns a Boolean value.

Prepared Property Remarks

Use the Prepared property to have the provider save a prepared (or compiled) version of the query specified in the ADO Command Object CommandText Property before a Command object's first execution. This may slow a command's first execution, but once the provider compiles a command, the provider will use the compiled version of the command for any subsequent executions, which will result in improved performance.

If the property is False, the provider will execute the Command object directly without creating a compiled version.

If the provider does not support command preparation, it may return an error as soon as this property is set to True. If it does not return an error, it simply ignores the request to prepare the command and sets the Prepared property to False.

Prepared Property Example

This Visual Basic example demonstrates the Prepared property by opening two Command objects: one prepared and one not prepared.

Public Sub PreparedX() 
Dim cnn1 As ADODB.Connection 
Dim cmd1 As ADODB.Command 
Dim cmd2 As ADODB.Command 
Dim strCnn As String 
Dim strCmd As String 
Dim sngStart As Single 
Dim sngEnd As Single 
Dim sngNotPrepared As Single 
Dim sngPrepared As Single 
Dim intLoop As Integer
` Open a connection. 
strCnn = "driver={SQL Server};server=srv;" & _ 
Set cnn1 = New ADODB.Connection 
cnn1.Open strCnn
` Create two command objects for the same 
` command -- one prepared and one not prepared. 
strCmd = "SELECT title, type FROM titles ORDER BY type" 
Set cmd1 = New ADODB.Command 
Set cmd1.ActiveConnection = cnn1 
cmd1.CommandText = strCmd 
Set cmd2 = New ADODB.Command 
Set cmd2.ActiveConnection = cnn1 
cmd2.CommandText = strCmd 
cmd2.Prepared = True 
` Set timer, then execute unprepared command 20 times. 
sngStart = Timer 
For intLoop = 1 To 20 
Next intLoop 
sngEnd = Timer 
sngNotPrepared = sngEnd - sngStart 
` Reset the timer, then execute the prepared 
` command 20 times. 
sngStart = Timer 
For intLoop = 1 To 20 
Next intLoop 
sngEnd = Timer 
sngPrepared = sngEnd - sngStart
` Display performance results. 
MsgBox "Performance Results:" & vbCr & _ 
" Not Prepared: " & Format(sngNotPrepared, _ 
"##0.000") & " seconds" & vbCr & _ 
" Prepared: " & Format(sngPrepared, _ 
"##0.000") & " seconds" 
End Sub