John Sansom SQL Server DBA in the UK

SQL Server DBA Blog, with straightforward advice, quality resources and musings about SQL Server

  • Home
  • About me
  • Books
  • How to Become a SQL Server DBA
  • Popular Posts
  • SQL Server Resources
  • UK SQL Server Events

DMV Query to identify all active SQL Server Sessions

Jun 3rd, 2009
by John Sansom.

You may already be aware that I am a big advocate of the SQL Server Dynamic Management Views (DMV’s) and the benifits that they bring to the Database Administrator. They certainly came in handy with a requirement I had recently whereby I needed to identify the IP Address of a specific SQL Server Login and so I would like to share my solution with you.

The query below identifies all currently active SQL Server user connections by their SQL Server Login name. It provides details of the IP address that the connection is sourced from, along with the number of sessions and connections that the SQL Server Login is currently responsible for.

SELECT
    B.login_name,
    A.client_net_address,
    NoOfConnections = COUNT(*)
FROM
    sys.dm_exec_connections A
		INNER JOIN sys.dm_exec_sessions B ON
			A.session_id = B.session_id
GROUP BY
    login_name,
    client_net_address

This is achieved by using two of SQL Server DMV’s:

  • sys.dm_exec_connections
  • sys.dm_exec_sessions


← Performing fast SQL Server delete operations
Generate a random number in SQL Server →
  • Pingback: SQL Snippet: SQL Server Wait Type Query | John Sansom - SQL Server DBA in the UK

  • Pingback: SQL Snippet: What SQL Server Agent Jobs were running at that time? | John Sansom - SQL Server DBA in the UK

  • Pingback: How to identify the most costly SQL Server queries using DMV's | John Sansom - SQL Server DBA in the UK

  • Pingback: SQL Snippet: Who owns that SQL Server Job? | John Sansom - SQL Server DBA in the UK

  • Pingback: How much memory is each SQL Server database using? | John Sansom - SQL Server DBA in the UK

  • Pingback: How to identify the most costly SQL Server queries using DMV's

  • Subscribe to RSS
  • Subscribe by Email
  • Search

  • Categories

    • Administration (54)
      • Disaster Recovery (7)
      • Dynamic Management Views (DMV) (4)
      • Index Optimisation (8)
      • Memory (2)
      • Reporting Services (5)
      • SQL Server Tips (19)
      • Tools (6)
    • Performance Tuning (18)
    • Professional Development (42)
      • Blogging (3)
      • Outstanding DBA Customer Service (5)
    • Query Optimisation (4)
    • SQL Server Community (130)
      • Reviews (1)
    • SQLServerCentral Syndication (65)
    • SQLServerPedia Syndication (63)
  • Archives

    • January 2012
    • December 2011
    • November 2011
    • October 2011
    • September 2011
    • August 2011
    • July 2011
    • June 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011
    • January 2011
    • December 2010
    • November 2010
    • October 2010
    • September 2010
    • August 2010
    • July 2010
    • June 2010
    • May 2010
    • April 2010
    • March 2010
    • February 2010
    • January 2010
    • December 2009
    • October 2009
    • September 2009
    • August 2009
    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009

Copyright John Sansom, 2009-2011, all rights reserved.