Wednesday 15 July 2015

How to get Total number of open connection In SQL Server

By using following syntax we could find total number of open connection in SQl server.
You could use where clause to know about specific database.

Syntax for all:

SELECT
    DB_NAME(dbid) as [Database Name],
    COUNT(dbid) as [Open Connections],
    loginame as [Login Name]
FROM
    sys.sysprocesses
WHERE
    dbid > 0
GROUP BY
    dbid, loginame;

For specific database:
WHERE
    dbid > 0
    AND DB_NAME(dbid)='your_db_name'

Tags: SQL server trick to know all open connection