如何检测孤立连接? [英] How to detect orphaned connections?
问题描述
一年多以前,我曾在论坛上问过类似的问题,但没有人回答.
我使用sp_who和sp-who2过程查询进程,但无法弄清楚如何有效检测孤立的连接/进程.
您将同意在大多数情况下应忽略LastBatch信息.
我想做一些工作或服务来记录一些有关服务器使用情况的统计数据.
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.
推荐答案
我认为孤立连接被分配了负的SPID,您可以从syslockinfo
(master db)like ...
I think orphaned connections are allocated a negative SPID, you can grab them fromsyslockinfo
(master db) like...
select * FROM syslockinfo WHERE req_spid=-2
这是有关该主题的文章
http://www.sqlserverclub.com/articles/how-to-deal-with-negative-spids-in-sql-server.aspx [
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
您是说从SQL方面还是从应用程序方面?您必须更加具体.您所说的孤立"连接是什么意思?就.Net应用程序而言,您应该始终在使用它后关闭连接.在给定的应用程序生命周期内保持打开数据库连接的理由很少.
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.
这篇关于如何检测孤立连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!