Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 747
  • Last Modified:

Dealing with Record Locking issues with SQL

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
weimha
Asked:
weimha
  • 2
2 Solutions
 
dbaSQLCommented:
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
 
dbaSQLCommented:
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
 
Aneesh RetnakaranDatabase AdministratorCommented:
- 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now