Re: How to lock an MSSQL server recordset for read?
- From: "Bob Barrows [MVP]" <reb01501@xxxxxxxxxxxxxxx>
- Date: Fri, 16 May 2008 11:47:37 -0400
Anders Eriksson wrote:
I have a database which has several tables. The main table has aThat's better. What you need to do is to start a transaction when you
column called OrderNo. I need to get the first available OrderNo from
this table, mark it as not available and the process the order.
since there are multiple programs doing this simultaneously I have
found that just opening a recordset and setting the Available value
to false and save it back to the database will not work since during
the time it takes
to set the Available column and update the database one or more other
programs will have done the same and multiple programs are now
processing the order.
So what I want is a way of locking the record in the database so that
only the first program can read this record and orderno.
I hope that I have expressed myself clear enough. If not please ask!
retrieve the order number from the table, and not commit the transaction
until the order is completely processed. This will essentially lock the
record from being updated by another process until the transaction is
complete, as well as relieve you of the necessity of marking the record
"unavailable" while the process is occurring. Whether you use ADO's
transaction functionality (connection.begintran) or SQL Server's in a stored
procedute depends on your process. How long will the processing take? Do you
already have all the data collected to perform the processing? If so, I
would use a stored procedure. If your process involves getting the order
number, and then collecting more data from the user, you shuld probably use
ADO's functionality ... but I would rethink this, what if the user does not
complete the process? Are you prepared to have to handle unlocking tables,
etc.?
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
.
- References:
- How to lock an MSSQL server recordset for read?
- From: Anders Eriksson
- Re: How to lock an MSSQL server recordset for read?
- From: Bob Barrows [MVP]
- Re: How to lock an MSSQL server recordset for read?
- From: Anders Eriksson
- How to lock an MSSQL server recordset for read?
- Prev by Date: Re: How to lock an MSSQL server recordset for read?
- Next by Date: Re: Could not update; currently locked error
- Previous by thread: Re: How to lock an MSSQL server recordset for read?
- Next by thread: Re: How to lock an MSSQL server recordset for read?
- Index(es):
Relevant Pages
|