Stefan Lotz
Stefan Lotz

Reputation: 1

equivalent of Oracles sys_context ('USERENV', 'SESSIONID') in SQLServer

I'm looking for the equivalent of oracle's

select sys_context ('USERENV', 'SESSIONID') from dual

on MS SQL Server.

I've googled this and found a lot of examples with sys.sysprocesses, sp_who, @@SPID

However @@SSPID seems to have a different meaning than the sessionid in oracle as it appears to be reused over the time. Is there a session identifier on MSSQL server that will not be reused?

Upvotes: 0

Views: 3874

Answers (1)

Stoleg
Stoleg

Reputation: 9290

You may try connection_id from sys.dm_exec_connections. In this view connection_id GUID looks like it might do your trick.

select connection_id, * from sys.dm_exec_connections

Upvotes: 1

Related Questions