question

sakuraime avatar image
0 Votes"
sakuraime asked DanGuzman edited

Azure sql database check current active running session and query

I would like to have a query to check in Azure sql database, where I can see the current running active query from which spid , user ,host,ip program . Any one has the idea ?

azure-sql-database
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AnuragSharma-08 avatar image
0 Votes"
AnuragSharma-08 answered sakuraime commented

Hi @sakuraime, welcome to Microsoft QnA forum.

You can run below query to get all the required information:

 select
     r.session_id,
     s.login_name,
     c.client_net_address,
     s.host_name,
     s.program_name,
     st.text, s.status
 from sys.dm_exec_requests r
 inner join sys.dm_exec_sessions s
 on r.session_id = s.session_id
 left join sys.dm_exec_connections c
 on r.session_id = c.session_id
 outer apply sys.dm_exec_sql_text(r.sql_handle) st
 where client_net_address is not null and text is not null and s.status = 'running'

Reference Article: Get username and/or IP address responsible for a query

Please let us know if this helps.


If answer helps, please mark it as 'Accept Answer'





· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

May I know how to trace down which query is running ??

suppose some one run


select from tableA
select
from tableB
GO



then the text will be


select from tableA select from tableB


but don't know it's running select from tableA or select from tableB


0 Votes 0 ·
DanGuzman avatar image
0 Votes"
DanGuzman answered DanGuzman edited

Consider using sp_whoisactive. This will show active queries along with resource utilization.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.