sql-serverdatabaseoracleuserinfo

Equivalent of Oracles sys_context ('USERENV', 'Client_Identifier') in SQL Server


I have been looking for equivalent of Oracles sys_context ('USERENV', 'Client_Identifier') in SQL Server.

I have been actively looking but got no correct answer, the above function is used in Oracle to identify the front end application user and I want to identify those application users in SQL Server. So far everywhere everyone is giving answers and I've looked into them but they are giving answers about database level, like which user is logged in right now on database but I want to identify the front end application user and use its email or name to insert into a field


Solution

  • Check out SP_SET_SESSION_CONTEXT to set a value

    https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-set-session-context-transact-sql?view=sql-server-ver15

    and SESSION_CONTEXT to retrieve it