I've found my program got exception as follows:-

----------------------------------------------
Exception: System.ArgumentException
Message: The SqlParameter with ParameterName 'XXXXX' is already contained by
another SqlParameterCollection.
Source: System.Data
at System.Data.SqlClient.SqlParameterCollection.Validate(Int32 index,
SqlParameter value)
at
System.Data.SqlClient.SqlParameterCollection.AddWithoutEvents(SqlParameter
value)
at System.Data.SqlClient.SqlParameterCollection.Add(SqlParameter value)
at System.Data.SqlClient.SqlParameterCollection.Add(Object value)
at GotDotNet.ApplicationBlocks.Data.AdoHelper.AttachParameters(IDbCommand
command, IDataParameter[] commandParameters)
at GotDotNet.ApplicationBlocks.Data.AdoHelper.PrepareCommand(IDbCommand
command, IDbConnection connection, IDbTransaction transaction, CommandType
commandType, String commandText, IDataParameter[] commandParameters, Boolean&
mustCloseConnection)
at
GotDotNet.ApplicationBlocks.Data.AdoHelper.ExecuteNonQuery(IDbConnection
connection, CommandType commandType, String commandText, IDataParameter[]
commandParameters)
at GotDotNet.ApplicationBlocks.Data.AdoHelper.ExecuteNonQuery(String
connectionString, CommandType commandType, String commandText,
IDataParameter[] commandParameters)
at GotDotNet.ApplicationBlocks.Data.AdoHelper.ExecuteNonQuery(String
connectionString, String spName, Object[] parameterValues)
...
----------------------------------------------

when I find out the problem I've found that my database already has that
record. So I wondor that why it does not throw exception like another
duplicate record something like ".... PK_XXXX ...." (duplication key). I've
got this exception in sometimes (the most is SqlException with violation key).

Someone may be wonder that why I do not post this to the board at GotDotNet.
Because I've already posted it and may be someone in this place can figure
out of my problem.

Thanks in advance,
Thana N.

RE: Duplicate record with wrong exception by PIEBALD

PIEBALD
Wed Mar 23 18:25:10 CST 2005

> Message: The SqlParameter with ParameterName 'XXXXX' is already contained by
> another SqlParameterCollection.

It looks to me like you're adding a parameter with a conflicting name to the
parameter collection. I did that once, now I use Parameters.Clear() before
reusing a Command.

RE: Duplicate record with wrong exception by ThanaN

ThanaN
Wed Mar 23 20:41:02 CST 2005

Sorry for my uncleared information. The program already has the line you told.
If I save the message that make the exception as a parameter of the function
to do
a testing. The exception always throw everytime this message is passed thru
the function. Event if the first time the program starts. But I cannot send
you the code, message, sp and database layout.

Thanks for your reply.

"PIEBALD" wrote:

> > Message: The SqlParameter with ParameterName 'XXXXX' is already contained by
> > another SqlParameterCollection.
>
> It looks to me like you're adding a parameter with a conflicting name to the
> parameter collection. I did that once, now I use Parameters.Clear() before
> reusing a Command.

RE: Duplicate record with wrong exception by PIEBALD

PIEBALD
Thu Mar 24 09:27:08 CST 2005

OK, the following code causes the same error. Notice I'm adding an instance
of a parameter to two commands or one command twice.

namespace Template
{
class Template
{
[System.STAThread]
static void Main(string[] args)
{
System.Data.SqlClient.SqlConnection con = new
System.Data.SqlClient.SqlConnection() ;
System.Data.SqlClient.SqlCommand cm1 = new
System.Data.SqlClient.SqlCommand ( "hi" , con ) ;
System.Data.SqlClient.SqlCommand cm2 = new
System.Data.SqlClient.SqlCommand ( "hi" , con ) ;

System.Data.SqlClient.SqlParameter prm = new
System.Data.SqlClient.SqlParameter() ;

cm1.Parameters.Add ( prm ) ;

// Either of these lines will cause the error
cm1.Parameters.Add ( prm ) ;
cm2.Parameters.Add ( prm ) ;

return ;
}
}
}

C:\>pt

Unhandled Exception: System.ArgumentException: The SqlParameter with
ParameterName 'Parameter1' is already contained by another
SqlParameterCollection.
at System.Data.SqlClient.SqlParameterCollection.Validate(Int32 index,
SqlParameter value)
at
System.Data.SqlClient.SqlParameterCollection.AddWithoutEvents(SqlParameter
value)
at System.Data.SqlClient.SqlParameterCollection.Add(SqlParameter value)
at Template.Template.Main(String[] args)

RE: Duplicate record with wrong exception by ThanaN

ThanaN
Thu Mar 24 21:11:02 CST 2005

Ok, I see. But my program injects the data like this about
2000 messages/day. And I've got the exception just a few,
the other sucess the job. Other infomation you should know
is I run this program in 2 computers to inject data from 2
sources (main, backup). So if you're right, how can I check
the duplication you've mentioned.

Thanks

"PIEBALD" wrote:

> OK, the following code causes the same error. Notice I'm adding an instance
> of a parameter to two commands or one command twice.
>
> namespace Template
> {
> class Template
> {
> [System.STAThread]
> static void Main(string[] args)
> {
> System.Data.SqlClient.SqlConnection con = new
> System.Data.SqlClient.SqlConnection() ;
> System.Data.SqlClient.SqlCommand cm1 = new
> System.Data.SqlClient.SqlCommand ( "hi" , con ) ;
> System.Data.SqlClient.SqlCommand cm2 = new
> System.Data.SqlClient.SqlCommand ( "hi" , con ) ;
>
> System.Data.SqlClient.SqlParameter prm = new
> System.Data.SqlClient.SqlParameter() ;
>
> cm1.Parameters.Add ( prm ) ;
>
> // Either of these lines will cause the error
> cm1.Parameters.Add ( prm ) ;
> cm2.Parameters.Add ( prm ) ;
>
> return ;
> }
> }
> }
>
> C:\>pt
>
> Unhandled Exception: System.ArgumentException: The SqlParameter with
> ParameterName 'Parameter1' is already contained by another
> SqlParameterCollection.
> at System.Data.SqlClient.SqlParameterCollection.Validate(Int32 index,
> SqlParameter value)
> at
> System.Data.SqlClient.SqlParameterCollection.AddWithoutEvents(SqlParameter
> value)
> at System.Data.SqlClient.SqlParameterCollection.Add(SqlParameter value)
> at Template.Template.Main(String[] args)

RE: Duplicate record with wrong exception by PIEBALD

PIEBALD
Fri Mar 25 09:41:05 CST 2005

I don't know.I think I've done all I can. Good luck.