Determine Username in Azure SQL Server if user is a User assigend managed identity

Viewed 135

I connect Azure SQL Server using a user assigned managed identity from a webapp. This works fine so fare, and our logging process shall log all activities of this app (and others) in the database.

To determine the username of the current acting user, i can usuallly use in any stored procedure something like

SELECT @ORIGINAL_LOGIN()

which will return the username of the connected user.

The username of the managed identity is in my case "octservice". But when "octservice" connects, and i log its activities, the @ORIGINAL_LOGIN() Function does not returns its username, it returns something like ClientID@TenantID from the Azure AD.

How can i anyway determine the username, like it appears in SSMS ? The ClientID@TenantID is not the USER_ID of this user.

enter image description here enter image description here

1 Answers

Try SELECT SYSTEM_USER()? It's a synonym for SUSER_SNAME(). I've seen it referenced once or twice with regard to managed identity.

Related