Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / T-SQL

How to Check Opened Connection in SQL Server

5.00/5 (2 votes)
13 Nov 2015CPOL 15K  
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.

SQL
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!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)