views:

38

answers:

2

is it possible to get MSSQL connection info?
not onli SUSER_ID(), SUSER_NAME(), ORIGINAL_LOGIN(), BUT other like:

  • IP
  • Connection string
  • ect..
+2  A: 

You can get some more information from sys.dm_exec_connections:

e.g.

SELECT * 
FROM sys.dm_exec_connections 
WHERE session_id = @@SPID

This will get the connection info available for the current process (SPID). This doesn't give the full connection string, but does give some more info like IP address (client_net_address).

This will work for SQL Server 2005 and above.

AdaTheDev
that is itthank younote:to take more info like host_name, program_name and otherSELECT *FROM sys.dm_exec_sessions ESJOIN sys.dm_exec_connections CN ON CN.session_id = ES.session_idWHERE ES.session_id = @@SPID
Anton
+2  A: 

You didn't mention the version of SQL Server that you're using, but this should work for SQL 2005 and above. You can change the @@SPID as needed.

SELECT
    conn.session_ID as SPID,
    conn.client_net_address as IPAddress,
    sess.host_name as MachineName,
    sess.program_name as ApplicationName,
    login_name as LoginName
FROM
    sys.dm_exec_connections conn
INNER JOIN sys.dm_exec_sessions sess ON
    conn.session_ID = sess.session_ID
WHERE
    conn.session_ID = @@SPID
Tom H.