The internal DataTable index is corrupt: '5'. Is used in the stream

I used a static global dataset shared between multiple threads.

I got the following exception:

The internal data table index is corrupt: "5".

In the streaming view, I read the value from the datatable and the update (used merge) value in the datatable as an ongoing operation in streaming mode.

+3
c #
Jun 30 2018-11-11T00:
source share
7 answers

You are performing operations on a set of data from different threads.

The dataset is not thread safe, you should make a wrapper class that protects the dataset from more than 1 operations at a time. This is called a mutex:

link to microsoft msdn

The best solution is to not use global state at all. This will fix your problem without extra work and make your code more reliable.

+2
Jun 30 '11 at 6:11
source share

If you use streams with a data set, this error will occur.

In my case, I was trying to create a new row for a data set in a method that was running in threads.

One way was to use SyncLock around a method that creates a string or another way (and probably even better) to create strings outside of threads.

Basically my code looks something like this:

  Dim elements As New List(Of element) Dim dataRows As New List(Of MyDataSet.Row) For i As Integer = 0 To elements.Count - 1 dataRows.Add(Me.Ds.Elements.NewElementsRow) Next Parallel.For(0, elements.Count, Sub(i As Integer) Me.CreateElementRow(elements(i), dataRows(i)) End Sub) 

In the CreateElementRow method , I do a lot of computation in threads.

Hope this helps.

+1
Dec 08 '15 at 11:01
source share

Well, since you use your dataTable in multiple threads, there is a high chance of corruption - if you are manipulating an object from different threads.

Some pointers to help you solve your problem:

  • Avoid using default views and changing the default view, if possible. Btw, .Net 2.0 has a read / write lock number when creating views, so they are not a problem that they were prior to 2.0.
  • Call AcceptChanges () where possible.
  • Be careful. Choose (expression) since there is no read / write lock in this code - and this is the only place (at least according to the person on usenet, so take this with a grain of salt - however, this is very similar to your problem, so use Mutexes help)
  • Set AllowDBNull to the column in the question (questionable value, but reported usenet - I used it only in those places where it makes sense)
  • Make sure you do not set null (C #) / Nothing (VB) in the DataRow field. Use DBNull.Value instead of zero. In your case, you may wish to make sure that the field is not zero, the syntax of the expressions supports IsNull (val, alt_val).
  • It probably helped me the most (it’s absurd how that sounds): if the value is not changing, do not assign it. For example, if you want to assign a value to a certain column, do it like:
 if (column.Expression != "some expression") column.Expression = "some expression"; 

Source of the answer: https://stackoverflow.com/a/2128778

0
Jun 30 '11 at 6:26
source share

Here is how I fixed my internal index, this is a corruption problem:

 System.Data.DataTable dtNew = new DataTable(); for (int iCol = 0; iCol < dtOriginalData.Columns.Count; iCol++) { dtNew.Columns.Add(dtOriginalData.Columns[iCol].ColumnName, dtOriginalData.Columns[iCol].DataType); } for (int iCopyIndex = 0; iCopyIndex < item.Data.Rows.Count; iCopyIndex++) { dtNew.Rows.Add(dtOriginalData.Rows[iCopyIndex].ItemArray); //dtNew.ImportRow(dtOriginalData.Rows[iCopyIndex]); } dtOriginalData = dtNew; 
0
Mar 23 '12 at 9:00
source share

Maybe you are using the same data in mutiple process @ at the same time. I just solved these problems using SYNCLOCK.

try it.

 SyncLock your datatable '''' -------your datatable process End SyncLock 

Please let me know if this helps you.

Happy coding.

0
Apr 20 '12 at 13:35
source share

To prevent execution in multiple threads, I used:

 Application.Lock(); --- do your stuff in the datatable Application.UnLock(); 
0
Jun 03 '14 at 13:15
source share
 DataTable.BeginLoadData(); // Do MultiThreaded Inserts DataTable.EndLoadData(); DataTable.AcceptChanges(); 

this will fix your problem.

0
Nov 11 '16 at 20:36
source share



All Articles