Introduction
Here
I will explain how to get or find number of active connections to database in SQL Server.
Description
Description
In
previous articles I explained Read XML file data using SQL Server, Joins in SQL Server, Get Latest Unique Records by count in
SQL Server,
Insert data with apostrophe in SQL
Server,
Convert Rows to Columns in SQL and many articles
relating to SQL
Server.
Now I will explain how to get or find
number of active connections to database in SQL Server.
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. |
|||
|
|||
1 comments :
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.
Note: Only a member of this blog may post a comment.