SQL Server trace based on client TCP port I have a Windows terminal server with many different users logging in via RDP to run an application. The application makes one or more connections per user to a SQL Server 2008 R2 instance. All users access the same database using the same SQL login. I would like to be able to trace a particular user's SQL session, but I have not found a way to determine which SQL session(s) belongs to which user. However, I am able to determine the source TCP port each instance of the application is using.

Is there a way to trace a SQL session based on the client's TCP port?
Is there a way to trace a SQL session based on the client's TCP port?


Yes. You can query sys.dm_exec_connections to identify a session from the client's TCP port (column client_tcp_port).

For example:

SELECT DEC.session_id
FROM sys.dm_exec_connections AS DEC
WHERE DEC.client_net_address = '192.168.0.100'
AND DEC.client_tcp_port = 63465;