Click here to Skip to main content
15,867,568 members
Articles / Programming Languages / T-SQL
Tip/Trick

How to Check Opened Connection in SQL Server

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
13 Nov 2015CPOL 14.1K   2   2
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)


Written By
Software Developer (Senior) Birla Soft
India India
Najmul Hoda is a Master of Computer Application.
He has worked with .Net technologies in web development and has been programming since 2007.
He is very comfortable in various languages,RDBMS,C# to VB.NET with Access & MS SQLServer from Javascript,AJAX to ASP.NET, MVC.


Khata Wata (Free Online Udhar Khata, Bahi Khata)
Download from play store


Comments and Discussions

 
GeneralNice Query Pin
aarif moh shaikh13-Nov-15 18:45
professionalaarif moh shaikh13-Nov-15 18:45 
GeneralRe: Nice Query Pin
Najmul Hoda27-Nov-15 3:49
Najmul Hoda27-Nov-15 3:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.