在我的应用程序中获取打开的连接字符串的数量

[英]Get Number of open connection string in my application


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?

我正在用c#和SQL Server 2008编写一个应用程序。如何获得尚未关闭的已打开连接的数量?

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

另外,如果我打开一个连接,超时时间为20分钟,并且没有关闭它——它会在20分钟后关闭吗?

2 个解决方案

#1


4  

This shows the no of connections per each DB:

这显示了每个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


1  

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

您应该能够针对SQL Server实例使用PerfMon SQL Server计数器来监视对应用程序外部服务器的开放连接……特别是当您的应用程序(很可能)从特定的连接中抽象出来时,如果您正在使用连接池,那么肯定是这样

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

这里有一篇关于某人演示问题并监视它的文章


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2010/12/20/4446cceaece64258b83e9d4b19e29f35.html



 
粤ICP备14056181号  © 2014-2019 ITdaan.com

赞助商广告