How to lock a record?


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
I have the need to update a field "InStockQty" with an accumulated value of "InStockQty + 100" or some other value. In VFP I used "RLOCK" to lock the record and make sure my update is done before allowing somebody else to update this field, now how can I do the same with SF/.NET/MS-SQL?


Edhy Rijo

Replies
Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
OK, this can get to be a complex topic.  However, there are in fact lots of examples out there on how to do this.  As you have probably already determined, doing this on a BO is not going to do any good as the data is disconnected.  You are going to have to do this as the SQL level.

There are a lot of samples out there.  Here are a few:

http://www.wwwcoder.com/tabid/68/type/art/parentid/191/site/6508/default.aspx

http://www.sqlteam.com/article/introduction-to-locking-in-sql-server

Another point here.  Depending on what you are trying to do, concurrency may be an option as well as record locking can very easily tie into concurrency.  For example, if you are using row versioning, it would be very easy to determine if someone else has touched that record when you save.  If so, then you can take it into account. 

Another option would be transactions.  Going through transactions can also play into the process here as when you start a transaction you can prevent anyone else from touching the records until the transaction is complete.  This is actually the approach that we take in our medical software when this could be a potential issue.

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Thanks Trent,

I think I will go with the Transaction since I want to try to keep all logic at the BO level since part of this application will escalate to be a Web Application.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
This is really the best way.  Smile
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search