Solved

SQL Server 2005 record lock

Posted on 2011-03-24
6
437 Views
Last Modified: 2012-08-14
I am currently have a locked record in a table called IV00101. There is some kind of lock on one record in this table. There is a part called 255A4330P001. I cannot even do a select statement against this part. If I try, the command just sits there running and the query never completes. Is there a sp I can run that will show me the lock currently on this record?
0
Comment
Question by:rwheeler23
  • 3
  • 2
6 Comments
 
LVL 39

Expert Comment

by:lcohan
ID: 35210343
you can try sp_lock and check for all locks on the objectid for your table
0
 
LVL 39

Assisted Solution

by:lcohan
lcohan earned 500 total points
ID: 35210396
You can replace the table_name in query below and try it on your server to find all lock for that object:

create table #locked_objects (spid int,dbid int,objid int,indid int,type sysname, resource sysname,mode sysname,status sysname)
insert into #locked_objects exec sp_lock
select * from #locked_objects where objid = object_id('table_name')


0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35210481
fyi:
select * from IV00101(nolock) where part= '255A4330P001' 

Open in new window

should work whatever lock is on the table/row ...
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:rwheeler23
ID: 35210714
OK, I have the SPID but how do I know which one is the lock? I see about a dozen records on this table. Do any of the columns tells me where the lock is?
0
 

Author Comment

by:rwheeler23
ID: 35215096
Rebooting the server was the only way to free up the lock. There were about 3 possible candidates. Restarting the SQL service would have accomplished the same thing.
0
 
LVL 39

Accepted Solution

by:
lcohan earned 500 total points
ID: 35217955
Next time you should try KILL SPID number instead of restarting the server and you can also use Activity Monitor (or SP_WHO2) to get more info about the process that's locking that badly to take action in the future.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now