Introduction
Here I will explain how to get or find number of active connections to database in SQL Server .
Description
Description
To get all information related SQL database connections we can use below queries
EXEC SP_WHO
OR
EXEC SP_WHO2
|
Above queries will return information about current users, sessions, and processes in an instance of the Microsoft SQL Server Database Engine. The information can be filtered to return only those processes that are not idle, that belong to a specific user, or that belong to a specific session.
If we run above queries we will get output like as shown below
Output:
If we want to see only active connections for specific database we need to write the query like as shown below
SELECT SPID,STATUS,PROGRAM_NAME,LOGINAME,HOSTNAME,CMD
FROM MASTER.DBO.SYSPROCESSES WHERE DB_NAME(DBID) = 'your database name' AND DBID != 0
|
In above query you need to replace 'your database name' with your database name. Once we replace with database name and if we run above query we will get output like as shown below
Output:
|
No comments:
Post a Comment