2 users updating the same row

Topics: Data Access Application Block, Enterprise Library Core, General discussion
May 16, 2007 at 12:48 PM
What is the preferred method to guard against 2 users updating the same row without knowing they are looking at the same row?

Is there an application block for this situation?

I am using a typed dataset.
May 16, 2007 at 1:58 PM
No application block for that scenario that I know of.

You are just talking about Database Concurrency Strategies when dealing with multi-user applications.

I have a tutorial that discusses Concurrency Strategies:

SQL Server Optimistic Concurrency Strategies

but in general I recommend asking this question in the ADO.NET Forum and looking at the data access tutorials on the Microsoft ASP.NET Website.

Regards,

Dave

______________________________

David Hayden
Microsoft MVP C#

May 17, 2007 at 1:01 PM
Thanks! that was what I was looking for.

DavidHayden wrote:
No application block for that scenario that I know of.

You are just talking about Database Concurrency Strategies when dealing with multi-user applications.

I have a tutorial that discusses Concurrency Strategies:

SQL Server Optimistic Concurrency Strategies

but in general I recommend asking this question in the ADO.NET Forum and looking at the data access tutorials on the Microsoft ASP.NET Website.

Regards,

Dave

______________________________

David Hayden
Microsoft MVP C#



May 17, 2007 at 1:59 PM
With the knowledge; more questions come.
I am using XSD to build my Datasets and until now, was in the habit of changing the SQL statements that VS2005 made for me. (Bad habit?)

After following your article I decided to use (in most cases) the TimeStamp (Strategy #4)
I also saw what you wrote about ConflictOption.CompareRowVersion enum of the SqlCommandBuilder.

1. So where in VS2005, can I tell the configurator of the XSD to use ConflictOption.CompareRowVersion?
2. If I have a “timestamp” column on the table and just change the update statement of the adapter to use WHERE (ItemID = @OriginalItemID) AND (timestamp = @Originaltimestamp) will I get an exception if it is not the same or just the TableAdapter.Update method will return 0 rows affected?
3. I assume I have to have the “timestamp” column in the select statement of the TableAdapter.

Thanks again! I was missing the term “concurrency” to understand the issue better.

Sep 16, 2009 at 5:48 AM

Hello ofergal

What you seemed to have implemented is the Optimistic concurency model. Is there any support for Pessimistic concurrency in DAAB. I am using EntLib 4.0.

Sep 16, 2009 at 8:42 AM

Hi,

I'm not sure what exact feature are you looking for with respect to the pessimistic concurrency. But looking at the ent lib source code, I found in the Unit test projects a method named "OneTransactionLocksOutAnother()" wherein if one transaction has lock to the table, the other transaction can't perform any process until the transaction ends. Is that what you are looking for?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 16, 2009 at 9:00 AM

Hi Valiant,

What I want can be best explained by a scenario where two users are accessing the same row in a web form (where data is in disconnected objects) and the changes made by the second user overwrites the changes made by the first. In this case I want to alert the second user while retrieving the record for editing that first user has already retrieved and is in the edit mode.

When first user is editing it then I want the second user to wait for a while which is the time gap given for any user to finish the updates. And then the second user can try for retrieving it again.

I guess this could be solved by using the timestamp column hoping that timestamp field automatically gets updated while select statements.

Sep 17, 2009 at 6:17 AM

Hi,

With what you've described, I may say, there is no out-of-the-box functionality that comes from DAAB.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Sep 17, 2009 at 6:26 AM
Edited Sep 17, 2009 at 12:28 PM

Thank you very much Valiant

I need to implement pessimistic concurency in the web application that I am currently developing. I believe that it should be handled through my business logic and the stored procedures(Database objects). Do you think it also requires to be handled through the Data Access layer? That would be the DAAB if my understanding about the tiers(layers) are correct?

Sep 26, 2010 at 6:14 AM

Hi,

Is there any Database Concurrency Strategies support at Enterprise Library 5?

Thank you very much.

Sep 27, 2010 at 12:49 AM

There isn't.  If you're using SQL Server, you may want to use the different transaction isolation levels for implementing database concurrency strategies.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com