Solved

Dealing with Record Locking issues with SQL

Posted on 2008-06-13
3
743 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

622 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