Concurreny with Datasets

G

Guest

Hi,

Is there a way to check if a records in the underlying database have been
updated by another client?

ds.HasChanges() method only tells you that the DataSet has changed from the
initial underlying data, but how do you know if another client has changed
the underlying data that you are just about to send changes to from your own
DataSet to?

Do you need to create a temporary DataSet to at the time of updating in
order to determine if any new changes exist against the modified original
rows?

Is this how its done?

thanks for any ideas in advance
Ant
 
C

Cor Ligthert [MVP]

Ant,

If you are using the commandbuilder, the standard by the wizards created or
yourself created sql string, than there is a select in that to check the
original that you have retrieved from the database to the current situation.

For that are now more methods in 2005 however assume the old method. In that
is checked every column if that what was original read by the dataadapter is
still the same. Is that not, than an error will be throwed and can you do
what you want to solve that. One of the probably most used options is
probably doing a rollback using the connection object..

I hope that this gives an idea?

Cor
 
G

Guest

Hi, Cor,

Thanks for the advice. I think that's probably the best way. I didn't
realize that optimistic concurrency was a default. Now I see that it throws
an error on finding the underlying data changed, I can work with that. Thanks
again.


Hello Miha,

Why would I want to know? well, I have a server with a few clients each
holding a Dataset derived from the data on the server. Datasets are
disconnected. If one user updates a row back to the server on one client,
then another user updates the same row from a dataset on another client, the
two different updates may cause data integrity problems. Which update would
be correct? (what if only col 1 was updated in update 1 but only col 2 was
updated in update two; I would lose the col 1 update).

So I need to control this.
Hope this helps

Thanks for your help
Ant

Miha Markic said:
Hi Ant,

Why would you need to know?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Ant said:
Hi,

Is there a way to check if a records in the underlying database have been
updated by another client?

ds.HasChanges() method only tells you that the DataSet has changed from
the
initial underlying data, but how do you know if another client has changed
the underlying data that you are just about to send changes to from your
own
DataSet to?

Do you need to create a temporary DataSet to at the time of updating in
order to determine if any new changes exist against the modified original
rows?

Is this how its done?

thanks for any ideas in advance
Ant
 
M

Miha Markic [MVP C#]

Hi Ant,

I think that you are not doing it right.
So, you check whether the data wasn't changed on database and then you do an
update if data wasn't changed, correct?
If so, then it is wrong and a performance hit. What if somebody changes data
between your check and your update?
See, you can't know that data wasn't changed before doing an update (unless
you heavily lock your database) and you don't need to.
Just try to do an update wrapped in a transaction and using concurrency
checking. If the update succeeds then it is ok, if it doesn't succeed then
you will know that data was changed and decide what do to.

HTH
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Ant said:
Hi, Cor,

Thanks for the advice. I think that's probably the best way. I didn't
realize that optimistic concurrency was a default. Now I see that it
throws
an error on finding the underlying data changed, I can work with that.
Thanks
again.


Hello Miha,

Why would I want to know? well, I have a server with a few clients each
holding a Dataset derived from the data on the server. Datasets are
disconnected. If one user updates a row back to the server on one client,
then another user updates the same row from a dataset on another client,
the
two different updates may cause data integrity problems. Which update
would
be correct? (what if only col 1 was updated in update 1 but only col 2 was
updated in update two; I would lose the col 1 update).

So I need to control this.
Hope this helps

Thanks for your help
Ant

Miha Markic said:
Hi Ant,

Why would you need to know?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Ant said:
Hi,

Is there a way to check if a records in the underlying database have
been
updated by another client?

ds.HasChanges() method only tells you that the DataSet has changed from
the
initial underlying data, but how do you know if another client has
changed
the underlying data that you are just about to send changes to from
your
own
DataSet to?

Do you need to create a temporary DataSet to at the time of updating in
order to determine if any new changes exist against the modified
original
rows?

Is this how its done?

thanks for any ideas in advance
Ant
 
G

Guest

Hi Miha,

Thanks for the tip. Using a transaction would certainly remove any further
risks that might occur during the update.
Cheers
Ant


Miha Markic said:
Hi Ant,

I think that you are not doing it right.
So, you check whether the data wasn't changed on database and then you do an
update if data wasn't changed, correct?
If so, then it is wrong and a performance hit. What if somebody changes data
between your check and your update?
See, you can't know that data wasn't changed before doing an update (unless
you heavily lock your database) and you don't need to.
Just try to do an update wrapped in a transaction and using concurrency
checking. If the update succeeds then it is ok, if it doesn't succeed then
you will know that data was changed and decide what do to.

HTH
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Ant said:
Hi, Cor,

Thanks for the advice. I think that's probably the best way. I didn't
realize that optimistic concurrency was a default. Now I see that it
throws
an error on finding the underlying data changed, I can work with that.
Thanks
again.


Hello Miha,

Why would I want to know? well, I have a server with a few clients each
holding a Dataset derived from the data on the server. Datasets are
disconnected. If one user updates a row back to the server on one client,
then another user updates the same row from a dataset on another client,
the
two different updates may cause data integrity problems. Which update
would
be correct? (what if only col 1 was updated in update 1 but only col 2 was
updated in update two; I would lose the col 1 update).

So I need to control this.
Hope this helps

Thanks for your help
Ant

Miha Markic said:
Hi Ant,

Why would you need to know?

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Hi,

Is there a way to check if a records in the underlying database have
been
updated by another client?

ds.HasChanges() method only tells you that the DataSet has changed from
the
initial underlying data, but how do you know if another client has
changed
the underlying data that you are just about to send changes to from
your
own
DataSet to?

Do you need to create a temporary DataSet to at the time of updating in
order to determine if any new changes exist against the modified
original
rows?

Is this how its done?

thanks for any ideas in advance
Ant
 

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