PDA

View Full Version : locking database records


dp_unsure
04-19-2003, 04:35 PM
could i request some advice?
when a record is locked by one user, and then a new user tries to update the record while it is locked would they receive an error. If they receive an erro whats the best way to handle it.

When a record is locked can another user still read it.

When an optimistic lock is used on a record, if two users try and update at the same time, what happens?

Thanks

miranda
04-19-2003, 05:36 PM
Remember that you are talking about ASP here and not a desktop application. Here is the chain of events in ASP
(1) a user requests a record
(2) the request comes into the webserver
(2) asp starts to process
(4) asp sees dataconnection object, connects to database
(5) the database serves up the info
(6) database connection is closed and released
(7) asp page is finished processing and transformed to html
(8) now gets sent to client
(9) user sees info on his/her computer


Note there is no active connection so the record cannot be locked.
So no error is ever thrown because of a locked record.
Any subsequent requests for the info will also get the info. Whoever has edit capability and hits edit first will edit the info, other users currently with that page loaded on their screen do not see the updates. Last person to edit overrides any and all changes previously made.

Odds of two users making simultaneous changes is rare but this will throw an error if it happens.