Yesterday we talked about how you can view the currently connected sessions to your SQL Azure instance. Doing so allowed for us to view the background sessions that were currently running tasks against our instance. Today we will look at the current connections and the sys.dm_exec_connections system view.
You can see all the current connections to your SQL Azure instance by running the following:
SELECT *
FROM sys.dm_exec_connections
By joining to the sys.dm_exec_sessions system view we can use the following query to more effectively monitor who is connected to our SQL Azure instance:
SELECT es.program_name, es.host_name,
es.login_name, COUNT(ec.session_id) AS [connection_count]
FROM sys.dm_exec_sessions AS es
INNER JOIN sys.dm_exec_connections AS ec ON es.session_id = ec.session_id
GROUP BY es.program_name, es.host_name, es.login_name
With that query you can poll your SQL Azure instance to track your connections at regular intervals. Tomorrow we will take a look at yet another SQL Azure system view that helps us see what activity is hitting our instance.
Thanks – had been looking for a replacement for sp_who to get SID and user host name
You are welcome! Also, keep in mind that Azure SQL Database v12 has MANY more DMVs for you to use these days, it’s quite close to the boxed version.