Multiple writers / rowlocking

D

DC

Hi,

I am implementing an app that will do massive updating on a DataTable
with multiple threads. Typically I first look up the row:

DataRow row = mydatatable.Rows.Find(key);

and then do some updating:

row.BeginEdit(); // here is where I get the exception

foreach (string colname in collist)
row[colname]=mydatacollection[colname];

row.EndEdit();

The problem is: in a multithreaded scenario the "BeginEdit" method
will raise an exception if the row is already being updated by another
thread. At least that's how the it looks to me. So I put a lock on the
row

lock (row)
{
row.BeginEdit();
....

but that didn't help. I could not find special sync objects on the row
level, so does someone know an efficient way to get this exception
over with?

Thanks in advance for any suggestion,

DC
 
D

DC

I spent quiet some time trying to fix this - to no avail. I believe
that the RecordManager of the SqlData classes is buggy when it comes
to massive multiple writers. I tried synchronizing with the only
object that I found supporting synchronization in these classes:
DataRowCollection. While putting a lock on DatarowCollection.SyncRoot
does produce less exceptions, it sooner or later will. Also, locking
the whole table is a bit coarse for my application, I need locks on
the row level.

The exception I get is a NullReferenceException

at System.Data.RecordManager.NewRecordBase()
at System.Data.DataTable.NewRecord(Int32 sourceRecord)
at System.Data.DataRow.BeginEdit()
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRow.set_Item(String columnName, Object value)
...(my method)

I will now start writing my own datahousekeeping class for this.

Regards

DC
 
K

Kris

http://users.pandora.be/pdo


please send me a personal email if you want to join in the development of
this project...


grtz

Kris



DC said:
I spent quiet some time trying to fix this - to no avail. I believe
that the RecordManager of the SqlData classes is buggy when it comes
to massive multiple writers. I tried synchronizing with the only
object that I found supporting synchronization in these classes:
DataRowCollection. While putting a lock on DatarowCollection.SyncRoot
does produce less exceptions, it sooner or later will. Also, locking
the whole table is a bit coarse for my application, I need locks on
the row level.

The exception I get is a NullReferenceException

at System.Data.RecordManager.NewRecordBase()
at System.Data.DataTable.NewRecord(Int32 sourceRecord)
at System.Data.DataRow.BeginEdit()
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRow.set_Item(String columnName, Object value)
...(my method)

I will now start writing my own datahousekeeping class for this.

Regards

DC


(e-mail address removed) (DC) wrote in message
Hi,

I am implementing an app that will do massive updating on a DataTable
with multiple threads. Typically I first look up the row:

DataRow row = mydatatable.Rows.Find(key);

and then do some updating:

row.BeginEdit(); // here is where I get the exception

foreach (string colname in collist)
row[colname]=mydatacollection[colname];

row.EndEdit();

The problem is: in a multithreaded scenario the "BeginEdit" method
will raise an exception if the row is already being updated by another
thread. At least that's how the it looks to me. So I put a lock on the
row

lock (row)
{
row.BeginEdit();
...

but that didn't help. I could not find special sync objects on the row
level, so does someone know an efficient way to get this exception
over with?

Thanks in advance for any suggestion,

DC
 
D

DC

Hi Kris,

interesting project but not exactly what I am into. My apps (dealing
with realtime information) usually work with data as dirty as possible
with as little rowlocking as possible - pessimistic rowlocking is the
worst I can run into.

I replaced the DataTable I used to store information with a class
derived from Hashtable and that threads great now. I can only
recommend to any ADO.NET users: if you really don't require many of
the ADO.NET classes' features and require multiple writers in a
mutithreaded scenario, then you are probably better off designing your
own class for this purpose; took me a couple of hours after debugging
the DataRow updating for three days. Even filling my class with data
(using an SqlDataReader) performs better than filling a DataTable with
the SqlAdapter since my class only produces the overhead I actually
need.

Regards

DC

Kris said:
http://users.pandora.be/pdo


please send me a personal email if you want to join in the development of
this project...


grtz

Kris



DC said:
I spent quiet some time trying to fix this - to no avail. I believe
that the RecordManager of the SqlData classes is buggy when it comes
to massive multiple writers. I tried synchronizing with the only
object that I found supporting synchronization in these classes:
DataRowCollection. While putting a lock on DatarowCollection.SyncRoot
does produce less exceptions, it sooner or later will. Also, locking
the whole table is a bit coarse for my application, I need locks on
the row level.

The exception I get is a NullReferenceException

at System.Data.RecordManager.NewRecordBase()
at System.Data.DataTable.NewRecord(Int32 sourceRecord)
at System.Data.DataRow.BeginEdit()
at System.Data.DataRow.set_Item(DataColumn column, Object value)
at System.Data.DataRow.set_Item(String columnName, Object value)
...(my method)

I will now start writing my own datahousekeeping class for this.

Regards

DC


(e-mail address removed) (DC) wrote in message
Hi,

I am implementing an app that will do massive updating on a DataTable
with multiple threads. Typically I first look up the row:

DataRow row = mydatatable.Rows.Find(key);

and then do some updating:

row.BeginEdit(); // here is where I get the exception

foreach (string colname in collist)
row[colname]=mydatacollection[colname];

row.EndEdit();

The problem is: in a multithreaded scenario the "BeginEdit" method
will raise an exception if the row is already being updated by another
thread. At least that's how the it looks to me. So I put a lock on the
row

lock (row)
{
row.BeginEdit();
...

but that didn't help. I could not find special sync objects on the row
level, so does someone know an efficient way to get this exception
over with?

Thanks in advance for any suggestion,

DC
 
Joined
Jul 18, 2007
Messages
1
Reaction score
0
Hi DC,
Can u share out yr class code to me as i am facing yr problem as well. Thanks in advance. My email is (e-mail address removed)

Regards,
Woo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top