×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Record lock and unlock

Record lock and unlock

Record lock and unlock

(OP)
Hello Genius Programmers,

i am converting VFP9 application DBF to SQL Server, in VFP i lock the record for other users and update the record. Through flowing code.

SELECT max_no
RL=.F.
DO WHILE.NOT.RL
RL=RLOCK()
ENDDO
qam=VAL(max_inv)+1
qam2= replicate('0',7-LEN(transform(qam)))+transform(qam)
isu_inv=TRANSFORM(qam2)
replace max_inv WITH isu_inv
UNLOCK

Please suggest me code for SQL Server. Mean lock the record and update table.

Thanks in advance.

RE: Record lock and unlock

SQL Server, besides other things, is a server. There are

a) other ways for counters. See integer IDENTITY(1,1) https://docs.microsoft.com/en-us/sql/t-sql/stateme...
and Sequences https://docs.microsoft.com/en-us/sql/t-sql/stateme...
b) have a server, that means requests are going through a queue, the server prioritzes a few things, usually you get what you want in chronoligical order of requests (sql) sent to the server, so you have less deadlocks. Locking is therefore something you rather not do to avoid deadlocks. You don't get concurrency situations mostly because sql server only executes in parallel what isn't acting on same resources. There are deadlocks, I actually experienced some with a scheduled task running an automatic data cleansing, but in general the queueing avoids such situations.

Having such an active central service works much better as clients acting on the data each by themselves and never knowing what other clients try at the same time, perhaps. It's a big advantage.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Record lock and unlock

Qamar,

What you are doing is called pessimistic locking. In other words, waiting until a lock is available before doing an update. (And that's not the best way to do pessimistic locking, but your question wasn't about that.)

SQL Server supports optimistic locking, not pessimistic. Basically, that means that you attempt to do the update, and worry about what happens if there is a collision (I'm simplifying this). You have to decide, for example, what to do if one user overwrites another's edits. Essentially that's a business decision, not a programming one.

Think about the effects of that sort of collision, then decide how to deal with it. For example, you might decide that a given user's updates is to have priority, or it might be more appropriate to combine the edits in some way. It's all a question of what is the correct solution in your application.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close