Introduction
Here
I will explain how to get or find number of active connections to database in SQL Server.
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:
|
If you enjoyed this post, please support the blog below. It's FREE!
Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.
|
Subscribe by RSS
Subscribe by Email
|
|
|
2 comments :
hai
There's an automatic way to handle that kind of process? My db always keeps the "awaiting command" cmd when some user makes the login on my C# application.
Could be treated from my app side?
Thanks again.