HiveBrain v1.2.0
Get Started
← Back to all entries
snippetsqlMinor

How do I use `sys.dm_exec_connections` in combination with SUSER_SNAME()?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
combinationdm_exec_connectionssuser_snamewithsyshowuse

Problem

How do I use sys.dm_exec_connections in combination with SUSER_SNAME()?

I want to see the username corresponding to each record in sys.dm_exec_connections.

Solution

As others have already pointed out the info you want is in sys.dm_exec_sessions. However if you want to pull from both DMVs this would work:

SELECT c.connect_time
 , s.login_time
 , s.host_name
 , s.login_name
FROM sys.dm_exec_connections AS c
   JOIN sys.dm_exec_sessions AS s ON c.session_id = s.session_id

Code Snippets

SELECT c.connect_time
 , s.login_time
 , s.host_name
 , s.login_name
FROM sys.dm_exec_connections AS c
   JOIN sys.dm_exec_sessions AS s ON c.session_id = s.session_id

Context

StackExchange Database Administrators Q#13124, answer score: 7

Revisions (0)

No revisions yet.