Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 a little shady...on locks?

Author  Topic 

jhermiz

3564 Posts

Posted - 2004-09-09 : 14:34:32
I feel I have read a few of the articles on records and what happens when two people or more are actually looking at a record and updating.

I get the feeling there is no definite answer on whose updates gets placed first? Could be the 1st / 2nd / nth ?

Is it basically based on whoever is updating first has control of the record?

I wonder if I need to implement some sort of check-in / check-out procedure ?

Thanks,


Jon
www.web-impulse.com

Can you dig it: http://www.thecenturoncompany.com/jhermiz/blog/

X002548
Not Just a Number

15586 Posts

Posted - 2004-09-09 : 15:34:22
Slim shady! I knew it...

Firts one in first update...followed closely by the second...so PLACE really is WIN



Brett

8-)
Go to Top of Page

jhermiz

3564 Posts

Posted - 2004-09-09 : 15:43:46
heh

ok thanks



Jon
www.web-impulse.com

Can you dig it: http://www.thecenturoncompany.com/jhermiz/blog/
Go to Top of Page

jhermiz

3564 Posts

Posted - 2004-09-09 : 15:44:25
so does that mean most of you implement checking in and checking out features ?

Jon
www.web-impulse.com

Can you dig it: http://www.thecenturoncompany.com/jhermiz/blog/
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-09-09 : 16:25:26
I don't... that's why are record history of everyhting they fo.

They will ALWAYS come back and say that

1). You're database is "broke" or
2). Another Miracle just happended...let's call the pope...

Most of the db's I set up have the data isolated to application groups, so the damage would be minimilazied...

Or to very specific accounts/users...


I must admit, even though...I either need to set up a history viewer so they can see how they screwed up (so I don't have to write ad hoc sql to investigate.....which is already a set of canned reports) or set up some procedure...

Never seemed worth the overhead....





Brett

8-)
Go to Top of Page

jhermiz

3564 Posts

Posted - 2004-09-09 : 16:28:26
Well the thing is I prolly need a way to not allow users or to at least warn users that a specific record is being worked on...so that the same person isnt sitting there and saving some changes while another one is doing the same thing ?

I can see it right now...2-3 different people sitting there modifying the same data and making saves on the record..only to find out they were overwritten by someone else ?


Jon
www.web-impulse.com

Can you dig it: http://www.thecenturoncompany.com/jhermiz/blog/
Go to Top of Page

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2004-09-09 : 22:27:34
you can force a row lock for the row being updated, but be sure to check if there is already someone with the lock in syslocks

hope this helps...
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-09-10 : 01:55:00
Have a "locks" table with the UserID + PK of records locked. In application disallow EDIT when the PK is in the table, owned by someone else.

Downside: If someone goes away from their workstation, or crashes, their "soft locks" remain.

We use an "Edit Number" in each table, incremented on each UPDATE (like a timestamp field). The UPDATE statement says

UPDATE MyTable
SET MyColumn = 'FOO'
WHERE MyPK = 'BAR' AND MyEditNo = 1234

the "1234" came from a SELECT, after the UPDATE the MyEditNo will be 1235, so another user following along trying to also do an update to MyEditNo=1234 will change 0 rows - i.e. error.

We do it this way 'coz we build web sites and everything is disconnected, so to speak.

Kristen
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-10 : 04:23:25
well i've worked on a project where we had an extra column "Editing" which was set to 1 when it was edited and back to 0 when updated. there was also a column UserId so we knew who was doing the update. history was also a part of an app.
soft locks as kristen put it, were solved by a timeout being set. when the user timed out his editing records were put back to 0. i didn't implement this but it acctually worked very well.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

jhermiz

3564 Posts

Posted - 2004-09-10 : 08:55:56
O yippie I just love programming...I am just so delighted to have to do this for the next 40 more years of my life.
NOTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT!!!!!

Jon
www.web-impulse.com

Can you dig it: http://www.thecenturoncompany.com/jhermiz/blog/
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-10 : 09:11:15
well, u can always go and become a hermit

Go with the flow & have fun! Else fight the flow
Go to Top of Page

jhermiz

3564 Posts

Posted - 2004-09-10 : 09:15:18
Heh

Sweet I wish :) if only they paid me to sit in a dark cave

Jon
www.web-impulse.com

Can you dig it: http://www.thecenturoncompany.com/jhermiz/blog/
Go to Top of Page

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2004-09-10 : 10:15:27
Jon --

is this locking issue in regards to your web project that you've been working on? If so, locking is really something you can't do in a web app. due to the disconnected nature of web browsers, you can't really show the user a row, lock it until they're done with it, and then update the row on the next submit. if the user just closes their browser, you're in big trouble, as the lock will never be removed.

it basically is a "last guy to update gets the change" deal with web apps, and make sure you have lots of validating at every step. i.e., if I edit customer 23, and then save it just as someone else has deleted customer 23, you need to make sure your UPDATE doesn't fail and return an appropriate error.

one way to handle this w/o locking, but still allowing for the users to have some idea of what is going on, is to make sure you have a "Last UPdated" column on your tables, which always has the date/time of the last change in each row. when you return a row to the user for editing, return the LastUpdated date to the page, and then submit the changed data along with that date. when your stored proc gets the data to update the row, it can check the current LAstUpdated with the one the user just submited, and if they don't match, issue an appropriate warning -- i.e, "Another user has also edited this record and saved changes before you did", or showing the two versions of the row and letting that user decide which to keep, or something along those lines.

just some ideas. of course, you still have traditional locking to deal with even in a web app, if they both submit their changes at the same time, and in a multi-step update two processes lock each other out.

just some thoughts, hope this applies.

- Jeff
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2004-09-10 : 10:16:07
quote:
Originally posted by Kristen

Have a "locks" table with the UserID + PK of records locked. In application disallow EDIT when the PK is in the table, owned by someone else.

Downside: If someone goes away from their workstation, or crashes, their "soft locks" remain.

We use an "Edit Number" in each table, incremented on each UPDATE (like a timestamp field). The UPDATE statement says

UPDATE MyTable
SET MyColumn = 'FOO'
WHERE MyPK = 'BAR' AND MyEditNo = 1234

the "1234" came from a SELECT, after the UPDATE the MyEditNo will be 1235, so another user following along trying to also do an update to MyEditNo=1234 will change 0 rows - i.e. error.

We do it this way 'coz we build web sites and everything is disconnected, so to speak.

Kristen




Wait...what's today's date...no, it's not April 1st...

You're kidding...right?



Brett

8-)
Go to Top of Page

jhermiz

3564 Posts

Posted - 2004-09-10 : 10:19:19
Jeff

Nah this is for a vb / sql server project I had worked on before. Its basically the next phase I am thinking about.
I seriously need help with my projects. I am juggling 3 apps that are already created, supporting them. Then I am
phasing this business development project (which was this thread). Plus I have to learn ASP.net to work on a global
IMS issues system. I'm NUTS I tell ya...NUTS

Jon
www.web-impulse.com

Can you dig it: http://www.thecenturoncompany.com/jhermiz/blog/
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2004-09-10 : 11:14:41
maybe persuading your boss to hire someone would help.

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-09-11 : 07:14:32
"Wait...what's today's date...no, it's not April 1st...

You're kidding...right?
"

Nope, absolutely serious. But very keen to learn the error of my ways!

Kristen
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2004-09-11 : 07:17:00
"return the LastUpdated date to the page"

Jeff,

Does a datetime have sufficient granularity to be guaranteed different?

e.g. Updates in quick succession in two separate SProc, each setting the LastUpdate to GetDate() [i.e. both updates set the same LastUpdate value] - could a web user get a read in between them?

Kristen
Go to Top of Page
   

- Advertisement -