MS SQL Table Locked by another user

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
skiko
Newbie
Posts: 8
Joined: Sun Dec 16, 2007 8:40 pm
Location: USA
Contact:

MS SQL Table Locked by another user

Post by skiko » Wed Oct 06, 2010 1:23 pm

New to databases, just using a simple dbconnect and dbexec.
having a problem with an Update script if locked by another user. Looking for a way to see if table is locked befor doing update or a way to pass along the SQL error to the user or log.

I am using macro Sched v12 with MS SQL 2005 I qet a quick error box that pops up but not on the screen long, I also get r=0 but also get the same if item is not in the databse.



DBExec>dbH,UPDATE ItemRecord SET basePrice= '%USELL%' WHERE itemCode='%UPC%',r

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed Oct 06, 2010 1:50 pm

I don't have MS SQL to test on, but something like this *might* help

Code: Select all

BEGIN TRAN
  SELECT *
  FROM ItemRecord WITH (XLOCK,READPAST) 
  WHERE itemCode='%UPC%


  UPDATE ItemRecord
  SET basePrice= '%USELL%'
  WHERE itemCode='%UPC%
COMMIT

skiko
Newbie
Posts: 8
Joined: Sun Dec 16, 2007 8:40 pm
Location: USA
Contact:

Need to test on a locked database but seems to work fine.

Post by skiko » Wed Oct 06, 2010 10:00 pm

Found this litle peace of code of interest

USE master
EXEC sp_lock2

not sure how to use it yet, but kinda cool
Thanks for your help

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts