dmpippin
5/10/2013 - 6:58 PM

SQL Example that finds Login, host name, program, Interface, Address and KB used

SQL Example that finds Login, host name, program, Interface, Address and KB used

SELECT 
  COALESCE(sess.nt_user_name,sess.login_name) AS LoginName,
  sess.host_name,
  sess.program_name,
  sess.client_interface_name,
  conns.client_net_address,
  memUsed.KBytesUsed
FROM sys.dm_exec_sessions sess
LEFT OUTER JOIN sys.dm_exec_connections conns
ON sess.session_id = conns.session_id
LEFT OUTER JOIN 
(SELECT 
  session_id,
  SUM(user_objects_alloc_page_count
      + user_objects_dealloc_page_count
      + internal_objects_alloc_page_count
      + internal_objects_dealloc_page_count) * 8 AS KBytesUsed
FROM sys.dm_db_task_space_usage
WHERE database_id = 2
GROUP BY session_id
)memUsed
ON memUsed.session_id = sess.session_id
--WHERE memUsed.KBytesUsed > 0
WHERE sess.session_id in (62,82)