Get Number of open connection string in my application

会有一股神秘感。 提交于 2019-12-22 09:43:03

问题


I'm programming an application with C# and SQL Server 2008. How can I get the number of opened connections that are not already closed?

Also if I open a connection with 20 minute timeout, and do not close it - will it closed after 20 minutes?


回答1:


This shows the no of connections per each DB:

SELECT 
    DB_NAME(dbid) as DBName, 
    COUNT(dbid) as NumberOfConnections,
    loginame as LoginName
FROM
    sys.sysprocesses
WHERE 
    dbid > 0
GROUP BY 
    dbid, loginame

And this gives the total:

SELECT 
    COUNT(dbid) as TotalConnections
FROM
    sys.sysprocesses
WHERE 
    dbid > 0

If you need more detail, run:

sp_who2 'Active'



回答2:


You should be able to use PerfMon SQL Server counters against the SQL Server instance to monitor open connections to the server external to your application...particularly as your application (likely) is abstracted from specific connections, definitely if you are using Connection Pooling

Here is a quick article on someone demonstrating the problem and monitoring it



来源:https://stackoverflow.com/questions/4487671/get-number-of-open-connection-string-in-my-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!