PRB: Error When You Combine ADO Refresh Method with CreateParameter (298118)
The information in this article applies to:
- ActiveX Data Objects (ADO) 2.0
- ActiveX Data Objects (ADO) 2.1
- ActiveX Data Objects (ADO) 2.5
- ActiveX Data Objects (ADO) 2.6
- Microsoft Data Access Components 2.0
- Microsoft Data Access Components 2.1
- Microsoft Data Access Components 2.5
- Microsoft Data Access Components 2.6
This article was previously published under Q298118 SYMPTOMS
ADO offers two methods to populate the list of input parameters that a parameterized stored procedure requires:
- The Refresh method of the Command object's Parameters collection, which makes a trip to the database server to retrieve the parameter list.
- The explicit CreateParameter method, which you use to build the parameter list in the client application.
If you combine the two methods, however, the list of parameters contains duplicates and generates ADO errors when you run the Command object. For example, Microsoft Data Access Components (MDAC) 2.6 and the Microsoft OLE DB Provider for SQL Server return the following error message:
Run-time error '-2147217900 (80040e14)':
Procedure or function [stored procedure name] has too many arguments specified.
CAUSE
If you call Parameters.Refresh to build the parameter list and then call CreateParameter, you effectively add each parameter to the list twice. When you try to run the Command, the error message informs you that you have more parameters than are defined in the stored procedure.
RESOLUTION
To work around this problem, use only one of the two above-mentioned methods to populate the Parameters collection. For performance reasons, Microsoft recommends that you use the CreateParameter syntax to avoid an unnecessary trip to the database server.
Modification Type: | Major | Last Reviewed: | 5/8/2003 |
---|
Keywords: | kbDatabase kbprb KB298118 |
---|
|