Troubleshooting
Problem
The following error may occur when running a .Net application: The DB2Parameter with ParameterName 'paramname' is already contained by this DB2ParameterCollection
Cause
This error is caused because two parameters of the same name are attempted to be added to the DB2ParameterCollection. Every parameter should have a unique name.
This error can easily be reproduced by modifying the sample .Net application shipped with DB2. Take the DbUse.vb sample which can be found both in the installation path (SQLLIB\samples\.NET\vb\) or in the DB2 Information Center a the following link:
http://pic.dhe.ibm.com/infocenter/db2luw/v10r5/topic/com.ibm.db2.luw.apdv.sample.doc/doc/dotnet_vb/s-DbUse-vb.html
If the follow lines are changed from:
cmd.Parameters.Add("@dept", DB2Type.SmallInt).Value = 70
cmd.Parameters.Add("@division", DB2Type.VarChar, 10).Value = "Eastern"
To these lines:
cmd.Parameters.Add("@dept", DB2Type.SmallInt).Value = 70
cmd.Parameters.Add("@dept", DB2Type.VarChar, 10).Value = "Eastern"
Essentially naming both parameters "@dept" rather than 2 unique names "@dept" and "@division", then the code throws the error message:
The DB2Parameter with ParameterName '@dept' is already contained by this DB2ParameterCollection.
Resolving The Problem
To resolve this issue, inspect the code that is throwing this error and correct the condition where the same parameter name is being used more than once. Each call to add a parameter should have a unique name.
Related Information
Was this topic helpful?
Document Information
Modified date:
16 June 2018
UID
swg21651972