简体   繁体   中英

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?

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

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'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM