473,396 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Locking a row...

I have a vb.net 2005 app that asks for a job number. After the job number
has been entered, I run an SQL 2000 stored procedure that selects the
appropriate row from the Jobs table. I do not want to allow another user to
make changes to that data, if another user has alreadyt selected that row
(i.e. row level locking).

How do I lock and check for a locked row in a stored procedure and then in
turn trap that error code in my vb app so I can then provide the appropriate
processing (i.e. inform user and do whatever I need)

Thanks, Brad
Jun 27 '08 #1
3 3756
You shouldn't really try to maintain a database lock on the row whilst the
user works on the record.

Either add a column to the row the indicate its locked (a "soft lock") which
you set from the relevant stored procedures or have a last modified column
that you set everytime the row is updated. With the latter you compare this
value with what you get when you read the row and what it is when you try to
update the row - if they are different then someone else has updated it and
you can advise the user accordingly.

Kind regards

Rob

"Brad Pears" <br***@truenorthloghomes.comwrote in message
news:uW**************@TK2MSFTNGP02.phx.gbl...
>I have a vb.net 2005 app that asks for a job number. After the job number
has been entered, I run an SQL 2000 stored procedure that selects the
appropriate row from the Jobs table. I do not want to allow another user to
make changes to that data, if another user has alreadyt selected that row
(i.e. row level locking).

How do I lock and check for a locked row in a stored procedure and then in
turn trap that error code in my vb app so I can then provide the
appropriate processing (i.e. inform user and do whatever I need)

Thanks, Brad
Jun 27 '08 #2
Brad,

There are two methods, optimistic concurrency and pessimistic concurrency
checking.

The pessimistic method is the oldest, the trouble with it was that it gave a
lot of trouble for the user and for the developper, because you had to
handle deadlocks as well. Think on an internet user which simple does not
reply after that he has got a page.

It is also a fact that there are (in most cases not all) only few changes
while there is much retrieved.

The optimisic concurrency is in fact the method standard implemented in Net
with generic procedures.

Optimistic concurrency is as Rob describes. The basic method is with all
the columns. But now the method with the "TimeStamp" the 'soft lock' can as
well be used in generic created SQL procedures. I don't know yet how these
optimistic methods are implemented in Linq to SQL.

As you are creating your SQL procedures by hand, then I advice you to use
the TimeStamp, as that is much easier then the all columns method. But you
cannot use that of course as there is no TimeStamp column in your table.

Cor
"Brad Pears" <br***@truenorthloghomes.comschreef in bericht
news:uW**************@TK2MSFTNGP02.phx.gbl...
>I have a vb.net 2005 app that asks for a job number. After the job number
has been entered, I run an SQL 2000 stored procedure that selects the
appropriate row from the Jobs table. I do not want to allow another user to
make changes to that data, if another user has alreadyt selected that row
(i.e. row level locking).

How do I lock and check for a locked row in a stored procedure and then in
turn trap that error code in my vb app so I can then provide the
appropriate processing (i.e. inform user and do whatever I need)

Thanks, Brad
Jun 27 '08 #3

despite what some people think T-SQL has a verry advanced and configurable
locking mechanism

Lock mode Description
Shared (S)
Used for read operations that do not change or update data, such as a
SELECT statement.

Update (U)
Used on resources that can be updated. Prevents a common form of
deadlock that occurs when multiple sessions are reading, locking, and
potentially updating resources later.

Exclusive (X)
Used for data-modification operations, such as INSERT, UPDATE, or
DELETE. Ensures that multiple updates cannot be made to the same resource at
the same time.

Intent
Used to establish a lock hierarchy. The types of intent locks are:
intent shared (IS), intent exclusive (IX), and shared with intent exclusive
(SIX).

Schema
Used when an operation dependent on the schema of a table is executing.
The types of schema locks are: schema modification (Sch-M) and schema
stability (Sch-S).

Bulk Update (BU)
Used when bulk copying data into a table and the TABLOCK hint is
specified.

Key-range
Protects the range of rows read by a query when using the serializable
transaction isolation level. Ensures that other transactions cannot insert
rows that would qualify for the queries of the serializable transaction if
the queries were run again.

http://msdn.microsoft.com/en-us/library/ms175519.aspx

If you need adavanced help about using isolation levels and / or lock
modes in Transact-SQL i recomend you to ask your questions in a SQL server
group
in SQL server programming ther are verry capable MVP`s availlable eager to
help you if you have interesting question for them , Uri Dimant for
instance has been a live saver for me several times with my SQL server
problems .

regards

Michel Posseth MCP
"Brad Pears" <br***@truenorthloghomes.comschreef in bericht
news:uW**************@TK2MSFTNGP02.phx.gbl...
>I have a vb.net 2005 app that asks for a job number. After the job number
has been entered, I run an SQL 2000 stored procedure that selects the
appropriate row from the Jobs table. I do not want to allow another user to
make changes to that data, if another user has alreadyt selected that row
(i.e. row level locking).

How do I lock and check for a locked row in a stored procedure and then in
turn trap that error code in my vb app so I can then provide the
appropriate processing (i.e. inform user and do whatever I need)

Thanks, Brad

Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Michael Chermside | last post by:
Ype writes: > For the namespaces in Jython this 'Python internal thread safety' > is handled by the Java class: > > http://www.jython.org/docs/javadoc/org/python/core/PyStringMap.html > > which...
3
by: Ryan | last post by:
I have a problem with record locking / blocking within an application. The app is quite straight forward. Written in Delphi 5 using BDE to access a SQL 7 database (Win2K server). Every so often...
9
by: john smile | last post by:
Hi All, I want to lock 2 tables on 2 servers using TABLOCKX hint. These tables function as semaphores in my application. It means when the tables are locked then other users will not be able to...
16
by: Nid | last post by:
How do I do row-level locking on SQL Server? Thanks, Nid
10
by: McFly Racing | last post by:
Thread Locking In Static Methods I have the need for a Log Manger class that has static methods. Normally I would use the lock statement or a Monitor statement both of which take a...
15
by: z. f. | last post by:
Hi, i have an ASP.NET project that is using a (Class Library Project) VB.NET DLL. for some reason after running some pages on the web server, and trying to compile the Class Library DLL, it...
7
by: Shak | last post by:
Hi all, I'm trying to write a thread-safe async method to send a message of the form (type)(contents). My model is as follows: private void SendMessage(int type, string message) { //lets...
0
by: xpding | last post by:
Hello, I have a class MyEmbededList contains a generic dictionary, the value field is actually the MyEmbededList type as well. There is another class need to access and manipulate a list of...
0
by: Cindy Huyser | last post by:
I have an Access 2000 database behind a threaded Java application that that can have have concurrent access to the same table (but not the same record). The database is set up for shared access...
1
by: Paul H | last post by:
I have an Employees table with the following fields: EmployeeID SupervisorID Fred Bob Bob John Bob Mary Bill Bill I have created a self join in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.