October 15, 2009 at 12:54 pm
I have some .Net developers that are opening a transaction to SQL, performing an insert/update and then killing the app in the middle. This is locking tha table. I ran dbcc opentran and it identified an open transaction but with a SPID that doesn't exist. It also shows a SPID with a letter attached to it (s). Below is the out put from the DBCC that I ran. The only way to delete the lock was to have them exit out of Visual Studio, but recently even that doesn't clear out the lock. Does anyone have an idea on how to find the SPID and delete the lock?
Transaction information for database 'Database1'.
Oldest active transaction:
SPID (server process ID): 74s
UID (user ID) : -1
Name : user_transaction
LSN : (800:830:1)
Start time : Oct 15 2009 2:19:34:390PM
SID : 0x60a478329b1a1349a3c8cea3bb229809
DBCC execution completed. If DBCC printed error messages, contact your system administrator.
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
October 15, 2009 at 1:00 pm
Just found out by stopping and starting DTC on developer's machine, freed the lock. But I should still be able to delete the lock through SSMS, no?
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
October 15, 2009 at 2:43 pm
Here is an article that I believe explains your issue and details a way to kill the negative spids
http://www.sqlserverclub.com/articles/how-to-deal-with-negative-spids-in-sql-server.aspx
andrew
October 17, 2009 at 7:12 pm
Cool article.... thanks, Andrew.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 18, 2009 at 6:56 am
Oh yes... Distributed transactions ...
If the app is killed (client side), msdtc can get stuck and sqlserver will need a non-standard way to get rid of the pending lock(s).
the referred URL is a very good resource !
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
October 19, 2009 at 4:43 pm
I thought the OP was trying to resolve a spid = -1; I poked around online and the only references to -1 spid were dealing with SQL 6.5(!)
As far as clearing -2 spids, realize that just because you SEE a -2 in master..syslockinfo does not mean it's a problem. Normally these will have a short lifetime; they SHOULD normally clear within a few seconds (in my environment, anyway). The exact "lifespan" is probably wildly variable depending on the environment.
So to clear -2 spids, first determin how long they normally last in your world. Once you figure that out, run something similar to this (assumes normal lifetime of 5 seconds, so we run once, wait 10 seconds, and run again):
--char 38 is single quote
select 'kill ' + char(39) + cast(req_transactionUOW as varchar(50)) + char(39) as RunThis from master..syslockinfo where req_spid = -2
WAITFOR DELAY '00:10' -- wait some time period (10 sec here) will likely be different based on your environment
select 'kill ' + char(39) + cast(req_transactionUOW as varchar(50)) + char(39) as RunThis from master..syslockinfo where req_spid = -2
--if it's in both selects, kill it! (maybe!)
If you see a UOW in BOTH resultsets, it's possible that it needs to be killed. You could certainly store the results from both SELECTs into a temp table (add a datetime column to differentiate run1 and run2)-- and do a query to only show the matches, but if you catch the problem quickly, there usually aren't that many to deal with.
Also-- don't worry if you get a UOW that contains all 0's and it does not clear-- don't bother trying to kill it.
October 20, 2009 at 9:14 am
Wouldn't a best practice be to free or kill the connection prior to app exit?
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply