Syncronize dataset with database in multithreaded application.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I have a multithreaded application that uses a typed dataset to held
configuration data. The configuration data is also stored in at database.
The dateset is send to the different threads using the byref keyword
From time to time i need to update the dataset in the application.
Using the fill method will work fine adding new rows to the dataset but
dont seem to work if a record has been removed from the database and there
for no longer should be in the dataset.
If I try to use the dataset.clear command before i use the load command it
works fine. But then i get rowerros arround in my application because the
refferenced rows no longer exists.

Do anyone have an idea how to update the dataset properly? without using the
clear method.

Best regards


jess
 
Jess Lundager Andersen said:
Hi
I have a multithreaded application that uses a typed dataset to held
configuration data. The configuration data is also stored in at database.
The dateset is send to the different threads using the byref keyword
From time to time i need to update the dataset in the application.
Using the fill method will work fine adding new rows to the dataset but
dont seem to work if a record has been removed from the database and there
for no longer should be in the dataset.
If I try to use the dataset.clear command before i use the load command it
works fine. But then i get rowerros arround in my application because the
refferenced rows no longer exists.

Do anyone have an idea how to update the dataset properly? without using
the
clear method.

First you don't need byref. The DataSet is a reference type, so it's
allways passed by reference.

The easiest pattern and most reliable pattern I know of for this is to
simply replace your DataSet instance with a new one periodically. The
clients will see the new data the next time they access the DataSet. Of
course you need make sure client code doesn't cache the reference to the
shared DataSet.

David
 
I hope you are doing locks to access that dataset.
Anyway, there is no magic method to do it for you. You could load data in an
empty copy of that dataset and then check out (by comparing) which rows were
deleted. Then delete the deleted rows from original dataset and then merge
the two.
But you'll still have problems if deleted rows are referenced..you should
notify the owner of reference that the row is no longer present or the owner
might check DataRow.RowState before dealing with the (possibly) deleted row.
 
Back
Top