473,835 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3802
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***@truenort hloghomes.comwr ote in message
news:uW******** ******@TK2MSFTN GP02.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***@truenort hloghomes.comsc hreef in bericht
news:uW******** ******@TK2MSFTN GP02.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***@truenort hloghomes.comsc hreef in bericht
news:uW******** ******@TK2MSFTN GP02.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
4577
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 has almost all of it public methods Java synchronized: > > http://cvs.sourceforge.net/viewcvs.py/jython/jython/org/python/core/PyStringMap.
3
5128
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 the users (when they bother to tell me) find that the application locks up and they are unable to work. No errors are produced (error trapping in the app is good). They 'shout round' to each other and get someone to exit the data entry screen....
9
5072
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 access them and automatically they can not continue their works. I have tried using the following code, but it does not work. I always got the error :
16
8937
by: Nid | last post by:
How do I do row-level locking on SQL Server? Thanks, Nid
10
11916
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 reference to (this). In the case of these static methods I am not able to do that.
15
6209
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 can't compile because the DLL is in use (and the PDB too), and the w3wp.exe process is the process locking the DLL (as viewed with Sysinternals - Process Explorer). this is a huge problem. i need to do IIS reset in order to free the DLL! 1. why is...
7
2872
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 send the messagetype via async NetworkStream ns = client.GetStream(); //assume client globally accessible
0
1325
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 MyEmbededList (please refer to the MyTestClass below). I am not sure whether I implements the right locking mechanism here and hope someone can give me some advices. I have provided some codes for these two classes below. My questions are: 1. Am I...
0
4104
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 with "No locks" as the default, so that optimistic record locking should take place, and "Open databases using record-level locking" is selected. Each Java thread gets a new connection to the database, then updates its record. One of my users has...
1
2230
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 the relationships window, with
0
10812
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10523
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10561
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10235
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9346
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5638
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4434
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3089
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.