The first thing would be to detect that a conflict exists between the data on screen and the data persisted in the databaseThe issue here is two users updating the table, not a conflict with data that already exists,
If an overlap/conflicting update is detected, a "merge" UI can be developed that can have both sets of values (values currently on screen and the values from the updated record)Do you have a demo of this?
The user can then choose which of the two values to keep and save the record into the database.Actually since they are updating the same record but not same fields, I would like a solution that preserves both.
CREATE TABLE TestConcurrency (ID int, Value char(1))
GO
INSERT INTO TestConcurrency
VALUES(1,'A')
,(2,'B')
BEGIN TRANSACTION
UPDATE TestConcurrency
SET Value ='C'
WHERE ID =1
BEGIN TRANSACTION
UPDATE TestConcurrency
SET Value ='D'
WHERE ID =1
The issue here is two users updating the table, not a conflict with data that already exists,I am slightly confused now. The statements above are contradictory - The question and the 2nd comment references updating the same record and hence the discussion on concurrency.
Actually since they are updating the same record but not same fields, I would like a solution that preserves both.
Do you have a demo of this?
So you can use BEGIN TRANSACTION / COMMIT to ensure concurrency in SQL Server.My situation here is that I'm using MS Access as FE and this deals with all commands to the BE, therefore not sure if I can apply this type of solution unless I re-design the entire app to be completely unbound and all changes will be done by code, something I would try to avoid at the moment.
The question and the 2nd comment references updating the same recordThats correct.
You could look into Pessimistic locking, which would prevent the User 2 from even beginning to edit the record until User 1 saves it. But that approach has its own problems too.That is something I would look into, wondering what are the problems I can expect..and where do I set this up?
+ User1 updates value of Field1 to 'A' with ID =1 at same time User2 updates value of Field2 to 'B' with ID =1. In this situation, what you are expecting?Really as stated above, I would prefer a solution that saves both changes, field1 & field2.
- The table must not have a RowVersion (aka TimeStamp) field, because its presence ensures full row concurrency.In general I knew that adding timestamp column causes less write conflicts, especially for tables with bit columns in them, therefore I'm afraid removing it may cause more harm than good..
We have an ADP Project (A2003) connected to SQL Server 2005.But then
We have a form bound to a large SQL table.....
I'm talking of Access build mechanism to talk directly with SQL w/o code intervention..
If AccessAs stated above, I dont see that option being avail in ADP.
Then use the way that Armen Stein suggested
By doing so, when a user performs a save, the system can detect whether or not someone else has already updated a record or not. If an overlap/conflicting update is detected, a "merge" UI can be developed that can have both sets of values (values currently on screen and the values from the updated record). The user can then choose which of the two values to keep and save the record into the database.
I have a few posts that I wrote on optimistic concurrency to help you get started: