The DB2Parameter with ParameterName 'paramname' is already contained by this DB2ParameterCollection from .Net application

Technote (troubleshooting)


Problem(Abstract)

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

DB2ParameterCollection.Add Method

Rate this page:

(0 users)Average rating

Document information


More support for:

DB2 for Linux, UNIX and Windows
DB2 Programming Interfaces - .NET

Software version:

9.5, 9.7, 10.1, 10.5

Operating system(s):

Windows

Reference #:

1651972

Modified date:

2013-10-17

Translate my page

Machine Translation

Content navigation