473,466 Members | 1,511 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Row Locking issue

Hi

here is what we want:
when process A selects a row for update, process B will only be allowed to
read only.

We are using DB2V8.2 Express Edition V8.2, and ODBC Driver is IBM DB2 ODBC
Driver. our application is C application.

the below is the SQL statements we have tried to lock the row, but none of
them works for me.

SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 WITH RS USE AND KEEP UPDATE LOCKS

SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 FOR UPDATE

SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 FOR READ ONLY WITH RS USE AND KEEP EXCLUSIVE LOCKS

we also alter the DBO_EMP table with the command:
ALTER TABLE DBO_EMP LOCKSIZE ROW

I would much appreciate it if you guy could help me on this.

- BLACK
Nov 12 '05 #1
5 4258
"black lee via DBMonster.com" <fo***@nospam.DBMonster.com> wrote in message
news:52******************************@DBMonster.co m...
Hi

here is what we want:
when process A selects a row for update, process B will only be allowed
to
read only.

We are using DB2V8.2 Express Edition V8.2, and ODBC Driver is IBM DB2 ODBC
Driver. our application is C application.

the below is the SQL statements we have tried to lock the row, but none of
them works for me.

SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 WITH RS USE AND KEEP UPDATE LOCKS

SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 FOR UPDATE

SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 FOR READ ONLY WITH RS USE AND KEEP EXCLUSIVE LOCKS

we also alter the DBO_EMP table with the command:
ALTER TABLE DBO_EMP LOCKSIZE ROW

I would much appreciate it if you guy could help me on this.

- BLACK


SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 FOR UPDATE

should keep a lock on the row until a commit is issued (auto-commit or
explicit commit statement). The lock will prevent other select for updates
on the same row, and other updates/deletes, but allow reads. This will
create a lock wait situation for other select for updates and
updates/deletes.

If it is not working, then you probably have auto-commit on.
Nov 12 '05 #2
Hi Mark,

thank you a lot for answering my question. how can I set auto-commit off?

- black

--
Message posted via http://www.dbmonster.com
Nov 12 '05 #3
black lee via DBMonster.com wrote:
Hi Mark,

thank you a lot for answering my question. how can I set auto-commit off?

- black


Autocommit is a client setting.
If you're using the DB2 CLP, check out the cli cfg (db2 get cli cfg).
If needed, you can alter the autocommit setting.

-R-
Nov 12 '05 #4
yes, the auto-commit was on, I have turned it off. but I am still unable to
lock the record if using the SQL:

SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 FOR UPDATE

I can see the record is locked from the monitor, but another process still
can access the record for update. I don't understand why.

it will lock the record if I use the SQL:

SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 WITH RS USE AND KEEP UPDATE LOCKS

--
Message posted via http://www.dbmonster.com
Nov 12 '05 #5
"Use and keep update locks" tells the database to use update type locks
instead of what it would normally decide to use. Since this is working;
I suspect that you are not obtaining the "U" lock on the row that you're
expecting the "for update" version to get. You've shown only the
SELECT statement; not anything else about the processing.

Your SELECT statement uses a cursor to provide positioning on the rows.
Assuming you are using CS isolation; the "U" lock on the row to be
updated, which prevents others from reading the row, should not be
obtained until the row had been read with a FETCH statement. Nothing in
your posts says anything about where you stopped the process to examine
the lock.

You stated that you can see the locks which implies that you have looked
at them using some tool. How about posting the actual lock states on
both the table and the row that BOTH applications have. Looking at the
lock differences for the two statements (that worked and didn't work)
will also give you clues as to what is happening.

Phil Sherman

black lee via DBMonster.com wrote:
yes, the auto-commit was on, I have turned it off. but I am still unable to
lock the record if using the SQL:

SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 FOR UPDATE

I can see the record is locked from the monitor, but another process still
can access the record for update. I don't understand why.

it will lock the record if I use the SQL:

SELECT t0.EMP_FNAME, t0.EMP_LNAME, t0.EMP_TITLE from DBO_EMP t0 where
t0.KEY = 60 WITH RS USE AND KEEP UPDATE LOCKS

Nov 12 '05 #6

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

Similar topics

12
by: Alban Hertroys | last post by:
Good day, I have a number of threads doing inserts in a table, after which I want to do a select. This means that it will occur that the row that I want to select is locked (by the DB). In these...
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
4
by: darrel | last post by:
I've been dealing with a file locking issue for a while. Our CMS spits out a new XML file each time an item in the DB is updated. This XML file is basically our site menu, and is what we use on...
2
by: tim | last post by:
I am really new to ASP.NET and I was wondering if most developers use locking hints when accessing the data in SQL Server. What kind of multi-user issues come up when using an ASP.NET application?
1
by: ABrown | last post by:
Hello, I have a 2003 database set up with about 20 users (only about 4 at a time) but I repeatedly get a problem with the records all locking. Each User is assigning billing codes to jobs so they...
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...
7
dlite922
by: dlite922 | last post by:
I need to do some sort of Locking mechanism at interface level, instead of DB Level. I know how MySQL table locking works, but that won't work in my scenerio. Requirements: When someone is...
9
by: zmickle | last post by:
Experts and books all say that you can share an Access back end on a shared drive with the front end running on each host computer. I have a simple database that tracks student data and it is...
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
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

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.