WCF and SQL Server - how to handle data change?

I have an application with an architecture like client / server / db. The connection between the client and server is WCF (was migrated from asmx), and the database is SQL Server 2005.

There is a requirement in the project that you cannot update an order that has been changed (updated) by another user after your initial reading. A common requirement in most applications, I think.

An order update is usually equal to:

  • The client reads the order - the original read copy (session) is stored on the server
  • Order client updates - returns the updated order to the server
  • The server again reads the order from the database and compares it with the original read for verification if the order has been changed by another user - in case the client is notified of the repeated reading of the order
  • The server will save the changes.

This method of processing data changes affects the fact that at a certain point (3) the server will have 3 (different) copies of the order in memory! Does anyone know a different strategy for this?

We run WCF with AspNetBackwardCompability because we need the Session variable to “hold” the original reads - this will make my day if we can reset this

+3
source share
4 answers

One solution is to ensure that the client delivers both the initially readable values ​​and the updated values ​​when saving. Then you do not need a copy of the original values ​​in the session.

(DataRowVersion.Original DataRowVersion.Current), (, Contract:

SaveMyData(MyType original, MyType updated);

:

UPDATE MyTable
SET Col1 = @NewCol1, Col2 = @NewCol2, ...
WHERE Col1 = @OldCol1, Col2 = @OldCol2, ...
IF @@ROWCOUNT = 0 ... update failed ...

TIMESTAMP/ROWVERSION . :

UPDATE MyTable
SET Col1 = @NewCol1, Col2 = @NewCol2, ...
WHERE PKCol = @PK AND TimeStampCol = @OldTimeStamp
IF @@ROWCOUNT = 0 ... update failed ...

, , , / . - , .

+2

3, 4?

, 3 ( , , ) , , (.. concurrency ). , , WHERE, , WHERE , , , .

no-op ( , , , @@ROWCOUNT OUTPUT), , , , .

+1

, , . - , . . concurrency , . sql, oracle , .

, .

+1

- , .

TIMESTAMP DataContract, WCF.

, . , , , FaultException . , , UPDATE, .

SQL Server TIMESTAMP (, , , / - , ), , DATETIME, SQL Server , . "" .

, , 8- - .

" TIMESTAMP (ROWVERSION) SQL Server".

0

Source: https://habr.com/ru/post/1712972/


All Articles