获取我的应用程序中打开连接字符串的数量 [英] Get Number of open connection string in my application

查看:52
本文介绍了获取我的应用程序中打开连接字符串的数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C#和SQL Server 2008对应用程序进行编程。如何获得尚未关闭的打开的连接数?

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?

如果我打开具有20分钟超时的连接,并且不关闭它-20分钟后它将关闭吗?

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

推荐答案

每个DB的连接数:

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

这得出总数:

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

如果需要更多详细信息,请运行:

If you need more detail, run:

sp_who2 'Active'

这篇关于获取我的应用程序中打开连接字符串的数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆