Search code examples
vbscriptasp-classicadodb

0x800a0e7c - ADODB.Parameters: Parameter object is improperly defined. Inconsistent or incomplete information was provided


I want to execute sql queries with parameters in classic asp. To do so I am using ADODB COMMAND object and an array of parameters, which I'm looping through and binding one parameter at a time to ADODB COMMAND object. See my below code:

 PRIVATE FUNCTION MapParametersToCommand(dbCmd, arrayParameters)
    FOR EACH parameter IN arrayParameters
        dbCmd.Parameters.Append dbCmd.CreateParameter(, GetDataType(parameter), 1, , parameter)            
    NEXT    
END FUNCTION

"GetDataType" is a method that is returning datatype and it's working fine. Over all method is working fine but in a particular scenario getting below exception:

0x800a0e7c - ADODB.Parameters: Parameter object is improperly defined. Inconsistent or incomplete information was provided.

In above code when we loop over array of parameters, when the parameter value is "%" it throws above exception. I've even tried to add extra single quotes ("'%'") but still getting the same exception. In this case datatype is coming as string (ie. 129 in number and correct as well) and value is "%" (tried with "'%'" ).

I found many similar question in which people got same error but the reasons were different than my case.

Things That I tried: 1. Added reference of adovbs.inc 2. Passing correct datatype 3. In debugger control goes to GetDataType method and comes back and then getting exception.


Solution

  • Pass in a value for the Size argument

    From the doc for CreateParameter Method (ADO)

    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.