If you read the documentation for CreateParameter()
all becomes clear;
If you specify a variable-length data type in the Type argument, you must either pass a Size argument or set the Size property of the Parameter object before appending it to the Parameters collection; otherwise, an error occurs.
As you are passing a VARCHAR
which is a "variable-length" data type you have to specify Size
when calling CreateParameter()
.
Dim cmd
Set cmd = Server.CreateObject("ADODB.Command")
With cmd
'Let the cmd deal with the connection.
.ActiveConnection = getConfigValue("ASPClassicConnectionString")
.CommandText = "[ReplyToEmailConfirmation]"
.CommandType = adCmdStoredProc
Call .Parameters.Append(.CreateParameter("@uniqueKey", adVarChar, adParamInput, 100))
.Parameters("@uniqueKey") = "dc8d8bfd-ea3a-4ad9-9f2d-92831eb2655a"
End With
Call cmd.Execute()
'Tidy up memory
Set cmd = Nothing
Also included CommandType
of adCmdStoredProc
which tells ADO to interpret this command as a Stored Procedure call, without it the default is adCmdUnknown
which means ADO has to attempt to workout what the command is, which however small adds an unnecessary overhead.
Also not a big fan of instantiating the ADODB.Connection
object just to execute a ADO.Command
object which then means you have to manage closing the ADODB.Connection
yourself. Instead let the ADODB.Command
do it for you, by passing a connection string letting it create the connection and destroy it itself. Assuming getConfigValue("ASPClassicConnectionString")
returns a connection string you can pass it directly to ActiveConnection
and the ADODB.Command
will instantiate the connection and dispose of it.
Useful Links