Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HELP ME... RECORD LOCKING PROBLEM

Status
Not open for further replies.

vijithamar

Programmer
Feb 14, 2002
29
0
0
IN
HI


please help me to change sql server locking option to TABLE LOCK to PAGE/ROW LOCK

I AM USING .NET + SQL SEVER 2005 EXPRESS

I tried like this :-

Code:
cmd.Connection = Conn
trn= Conn.BeginTransaction()
cmd.Transaction = trn

For i=1 to NumOfProd 
  cmd.CommandText = "Update batch set stock=" & vqty & "   where batchid=" & vid
  cmd.ExecuteNonQuery()

Next i
trn.commit
my problem is, entier table 'Batch' get locked for updation until the commit statement. other computers has to wait until the For-Loop gets over


i tried 'WITH (ROWLOCK)' option in update statement but no effect.

Thank you
Viju


please help me
 
That's the way that transactions work. You need to either remove the transaction or commit more often.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
if the other computers or processes don't need to write to that table, then you can get them to return data by making sure you use with (nolock, readuncommitted) options against the table in a select query.

--------------------
Procrastinate Now!
 
Maybe you should consider not using a loop. ANd perhaps I'm missing something, but since you don't seem to change the variables in the update with each loop, you seem to be running the exact same update repeatedly.

Perhaps you could give us an example of the data you have and the results you want and we could help you find a set-based (much faster) way to perform the action.

"NOTHING is more important in a database than integrity." ESquared
 
thanks for your replay

There are some code within the loop i omitted...

My problem is about locking. why all the records get locked once a single row is updated(when i=1). row level locking is not happing here...


thanks
 

sorry... it was "happening"

Thanks... it was the problem with indexing. its working now

bye.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top