Hashtable key being added twice error and possible solution
Posted by: Matt
Date: December 09, 2006 03:28PM

I decided to make this its own topic, since the other topic where this is posted is getting long.

Item has already been added. Key in dictionary: '?p2' Key being added: '?p2'

I found in the Connector/Net 5.0.2 code where this error occurs. In the parameter_collection.cs file on lines 115 and 116:

115 hash.Add(value.ParameterName, index);
116 ciHash.Add(value.ParameterName, index);

I'm not a C# programmer and I don't know what impact this has, however, I changed the code to the following, and now it works as expected.

115 if (!hash.ContainsKey(value.ParameterName))
116 {
117 hash.Add(value.ParameterName, index);
118 }
119 if (!ciHash.ContainsKey(value.ParameterName))
120 {
121 ciHash.Add(value.ParameterName, index);
122 }

Using Console.Write, I found that the code in the if statatements is still being executed. However, every few executions, it stops parameters ?p2 and ?p3 from being added to the hashtables hash and ciHash a second time. I'm not sure why the problem occurs, but the above seems to fix it. I will test it some more and post the results.

I don't use parameters in my queries (except what the command builder adds automatically), so this change may affect queries that do.

If anyone else is having this problem (James Pearson), either make the chages mentioned above or download the dll at http://www.noinx.com/MySql.Data.zip
I also don't know how this affects projects using the Visual Studio Plugin. So, use at your own risk.

Any comments from the developers???

-Matt

-------------Original Post-----------------

Item has already been added. Key in dictionary: '?p2' Key being added: '?p2'

Using an adapter and command builder, the first time I update, there is no problem. However, sometimes an update will work the second time, but usually doesn't, when updating more than one row at a time.

I will try going back to connector/net 5.0.1 or 1.0.8 tomorrow, when I have more time.

CB.RefreshSchema()
Dim Changes As New DataTable
Changes = Data_Table.GetChanges
Adapter.Update(Changes)
Data_Table.AcceptChanges()
Data_Table.Clear()
Adapter.Fill(Data_Table)


-Matt
Connector/Net 5.0.2
MySql 5.0.22
Windows XP Pro Client/Server

----------------End------------------



Edited 1 time(s). Last edit at 12/10/2006 04:47PM by Matt .

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.