65.9K
CodeProject is changing. Read more.
Home

How to Check Opened Connection in SQL Server

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Nov 13, 2015

CPOL
viewsIcon

14983

Here is the code snippet to check how many database connections are opened in SQL Server.

Introduction

Sometimes, we need to know how many database connections are opened in SQL Server. So here is the code snippet that we can use to get a number of opened connections per database.

SELECT
[DATABASE] = DB_NAME(DBID), 
OPNEDCONNECTIONS =COUNT(DBID),
[USER] =LOGINAME
FROM SYS.SYSPROCESSES
GROUP BY DBID, LOGINAME
ORDER BY DB_NAME(DBID), LOGINAME

When you run the above code, you will get a result something like below:

Enjoy reading!