Solved

Dealing with Record Locking issues with SQL

Posted on 2008-06-13
3
739 Views
Last Modified: 2008-06-23
My company mainly works in the iSeries environment with RPG programs.  In the RPG programs we have record level access of our files meaning when a record is read it is locked and cannot be accessed by another program trying to update it.  

We have started to make the jump from RPG to C# and ASP.Net applications, still using the iSeries as the database.  As far as I can tell there is no record locking when using SQL in these applications.  I am using iDB2 for ADO.net for a connection to the iSeries.  

Could someone please let me know how you handle record locking when using SQL?  In specific, how do you keep two people from not trying to update the same record at the same time?  I'm interested in ways to do this using both the iSeries and MS SQL server.

Thanks
0
Comment
Question by:weimha
  • 2
3 Comments
 
LVL 17

Expert Comment

by:dbaSQL
ID: 21778263
sql server has different types of locks -- (row locks, table locks, database locks, etc.  see BOL).  
sql handles locking automatically, but it can be customized.
i believe in your case you may want to use table-level, or even row-level locking hints.
(see 'Hints' in Books Online)

for example, if you were going to do an update, you would do something like this:

update tablename with (rowlock)
set whatever........

0
 
LVL 17

Assisted Solution

by:dbaSQL
dbaSQL earned 200 total points
ID: 21778312
also, you may wish to review setting the transaction isolation level.  again, see BOL, but sql has different transaction isolation levels, which handle the locking

SERIALIZABLE:
Places a range lock on the data set, preventing other users from updating or inserting rows into the data set until the transaction is complete. This is the most restrictive of the four isolation levels. Because concurrency is lower, use this option only when necessary. This option has the same effect as setting HOLDLOCK on all tables in all SELECT statements in a transaction.

0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 300 total points
ID: 21778622
- do those operations in a single transaction
- change the isolation level to serializable (not advised )
- add a 'timestamp' column and read that value before doing the update
  and during the update pass that value in the where condition, the timestamp columns will updated automatically, whenever a row is modified

Aneesh
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question