Girish
Girish

Reputation: 447

Total sql connection consuming by application

I have multiple C# applications and all applications use the same database(SQL server 2014) and same credentials(Same connection string). All application run on the same server.

Now, my question is anyhow can I get the total number of SQL connections consuming(current open connection) by particular application right now?

I.e

     1. 3 connections open in Application1
     2. 2 connections open in Application2

I tried using "App Name" in connection string but I don't know how to get total connection consuming by "App Name"?

Upvotes: 0

Views: 727

Answers (2)

Girish
Girish

Reputation: 447

I also found another sql query to get open connection application wise.

SELECT count(*),program_name
FROM master.dbo.sysprocesses sp 
group by program_name

Upvotes: 0

Alex K.
Alex K.

Reputation: 175766

Query the Dynamic Management Views:

SELECT 
    COUNT(*),
    program_name
FROM 
    sys.dm_exec_connections cn
LEFT JOIN 
    sys.dm_exec_sessions sn
ON 
    sn.session_id = cn.session_id
GROUP BY 
    program_name

Upvotes: 1

Related Questions