Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Over a year ago I've asked similar question on forums, but no one answered.

I use sp_who and sp-who2 procedures for querying processes, but I can't figure out how to effectively detect orphaned connections/processes.
You will agree that LastBatch information should be ignored in most cases.

I would like to make job or service for logging some statistical data about server usage.
Posted

I think orphaned connections are allocated a negative SPID, you can grab them from syslockinfo (master db) like...

SQL
select * FROM syslockinfo WHERE req_spid=-2


Here's an article on the subject

http://www.sqlserverclub.com/articles/how-to-deal-with-negative-spids-in-sql-server.aspx[^]

Google for req_spid=-2 and you'll get a few hits on the subject
 
Share this answer
 
Comments
Oshtri Deka 14-Apr-11 15:08pm    
I'll check it out tomorrow.
Do you mean from the sql side of things or the application side? You gotta be a lot more specific. And what do you mean by "orphaned" connections? As far as a .Net application goes, you should ALWAYS close a connection after using it. There are few reasons to keep a database connection open for the life of a given application.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900