Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Locking a SQL Server Record from ASP + Batch Transactions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
David C. Barber - 27 Sep 2007 03:27 GMT
How do you lock a record in SQL Server from ASP 2?  I need to read the
record, allow the user to edit it, and then have them click Save and rewrite
it.  Obviously I don't want anyone else getting into this record while the
user has it up.  I don't see how to have SQL Server lock this record for me
since the connection drops the moment the page is written, and would prefer
to avoid the kludge of adding and handling reservation fields to each record
if there's a better way.

Also, although I've set up batch transactions in VB6 w/o problems, I'm not
sure how to best do that in VB NET using a Sql Server Control.   I'm not
sure if I have the same access to the connection that I do on VB6 ADO.

Thanks!
Aidy - 27 Sep 2007 09:54 GMT
What you're doing is basically a bad idea.  What happens if the user locks
the record then goes away for lunch, shuts their browser down, has a power
cut etc?  You should never hold locks across page processes, you'll have to
kludge it by adding a "editing by" type field or some other solution.
You're main problem is going to be issues with how long you want these
records to remain locked for.

> How do you lock a record in SQL Server from ASP 2?  I need to read the
> record, allow the user to edit it, and then have them click Save and
[quoted text clipped - 13 lines]
>
> Thanks!
David C. Barber - 03 Oct 2007 06:44 GMT
Aidy,

Thanks for the thought, and yes that can be a hazard.  So can having two
people trying to edit the same record at the same time.

I would expect that if someone locks a record and goes away for lunch, the
session terminates in 20 minutes, any connection to the SQL Server database
goes away, and the lock drops out.  The problem here is that standard
database locking may not work at all since the connection actually drops the
moment the page is written, since this is a stateless system.

And btw, you solution of setting up a reservation field to kludge it has
exactly the same problem as locking the record.  Someone goes away with the
reservation field set, and no one else is allowed to get to it.

> What you're doing is basically a bad idea.  What happens if the user locks
> the record then goes away for lunch, shuts their browser down, has a power
[quoted text clipped - 20 lines]
> >
> > Thanks!
Aidy - 03 Oct 2007 09:38 GMT
> And btw, you solution of setting up a reservation field to kludge it has
> exactly the same problem as locking the record.  Someone goes away with
> the
> reservation field set, and no one else is allowed to get to it.

Yes but that is a logical problem.  Such systems could tell you "This record
is locked by so-and-so and has been for 25 minutes.  Do you want to override
their lock?".  Whereas if you have a SQL lock people are physically
prevented from accessing the data at all until a sysadmin comes along and
starts killing processes.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.