Finding the number of sessions and requests currently active in your Azure SQL database(s)

Posted: (EET/GMT+2)

 

Sometimes, it is useful to know the current state of your application when monitoring load. The new Azure web portal does a good job in giving you the details, but what if you want to know these details in code? For instance, you might wish to have an admin section in your ASP.NET web application, and display current SQL database state there.

Here are two useful SQL statements to use:

SELECT COUNT(*) AS [Sessions]
FROM sys.dm_exec_connections

SELECT COUNT(*) AS [Concurrent_Requests] 
FROM sys.dm_exec_requests

These queries return the current number of session and concurrent requests (queries, usually) in progress.

Actually, these same queries work in traditional on-premises SQL Server installations.