DataTable and NewRow problem

  • Thread starter Thread starter Jason Callas
  • Start date Start date
J

Jason Callas

I have a process that manages a list of trades. Each trade is a separate row in the table. I blast the process with 10,000 new trades in order to stress test it and end up with the below listed exception when I call the NewRow method. The number of times it happens is NOT consistent (sometimes a few times out of 10,000 and sometimes 1000+ times). The app is written in VB and I am using SyncLock everywhere the table is accessed but I am sure it is still some concurrency issue.


Code ==>

' create new execution row
SyncLock _executionMonitor
exec = _tradeTable.NewRow
End SyncLock

Execption ==>

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index) ( at System.Collections.ArrayList.get_Item(Int32 index)
at System.Data.RecordManager.NewRecordBase()
at System.Data.DataTable.NewRecord(Int32 sourceRecord)
at System.Data.DataTable.NewRow(Int32 record)
at System.Data.DataTable.NewRow()
at LaBranche.Barracuda.TradeManager.OnEntryMessageReceived(Object sender, MessageEventArgs e))


Any thoughts are appreciated. Thanks.

- Jason
 
Hi Jason,

What is has the SyncLock to do with the concurrency problems.

A datatable is disconnected. It is not a recordset.

So you can add as much rows as you want except you can not create rows with
duplicated primary keys.

How do you add rows to your table, because it says that the index is/becomes
incorrect.

However maybe I miss something and than I am curious about that?

Cor



Hi
"Jason Callas" <[email protected]> schreef in bericht
I have a process that manages a list of trades. Each trade is a separate row
in the table. I blast the process with 10,000 new trades in order to stress
test it and end up with the below listed exception when I call the NewRow
method. The number of times it happens is NOT consistent (sometimes a few
times out of 10,000 and sometimes 1000+ times). The app is written in VB
and I am using SyncLock everywhere the table is accessed but I am sure it is
still some concurrency issue.


Code ==>

' create new execution row
SyncLock _executionMonitor
exec = _tradeTable.NewRow
End SyncLock

Execption ==>

Index was out of range. Must be non-negative and less than the size of the
collection.
Parameter name: index) ( at System.Collections.ArrayList.get_Item(Int32
index)
at System.Data.RecordManager.NewRecordBase()
at System.Data.DataTable.NewRecord(Int32 sourceRecord)
at System.Data.DataTable.NewRow(Int32 record)
at System.Data.DataTable.NewRow()
at LaBranche.Barracuda.TradeManager.OnEntryMessageReceived(Object sender,
MessageEventArgs e))


Any thoughts are appreciated. Thanks.

- Jason
 
I am not sure if it is a synclock problem at all. (I do have more than one
thread using the tablem hence the use of synclock).

The problem is not when I add the row but when I go to create a new row. If
you look at the exception you see that it is being thrown internally to the
DataTable on the NewRow method.

- Jason
 
Hi Jason,
The problem is not when I add the row but when I go to create a new row. If
you look at the exception you see that it is being thrown internally to the
DataTable on the NewRow method.
That is as I said, however some code how you create a new row can show a lot

With that I did mean show us some code where the new row is created and
added..
(and not more, this should normally be enough)

Cor
 
I did in the first posting but here it is again.

I have been unable to create a small application that can reproduce the
problem (for posting purposes). There are libraries that are used to submit
the trade (via thrid party middleware) and others that are used to validate
that cannot be posted.

I did put a try/catch block around just the NewRow method that was causing
the exception to confirm that it was the code inside DataTable that was the
problem.

Try
SyncLock _executionMonitor
exec = _tradeTable.NewRow
End SyncLock
Catch ex as Exception
' sometimes the above code causes an exception
' Index was out of range. Must be non-negative and less than the
size of the collection.
' Parameter name: index) ( at
System.Collections.ArrayList.get_Item(Int32 index)
' at System.Data.RecordManager.NewRecordBase()
' at System.Data.DataTable.NewRecord(Int32 sourceRecord)
' at System.Data.DataTable.NewRow(Int32 record)
' at System.Data.DataTable.NewRow()
' at
LaBranche.Barracuda.TradeManager.OnEntryMessageReceived(Object sender,
MessageEventArgs e))
End Try

Sorry I cannot provide more info but maybe somebody else has run into this
problem.

- Jason
 
Its a DataRow of course. (NewRow method of DataTable class only returns
DataRow objects.)

But nevermind on the whole thing. If you have not experienced this problem
you will not figure it out....

I am just going to change everything and use hashtables and arraylists.

- Jason
 
Back
Top