Here’s the problem in short. I have a desktop application that connects to a SQL Server database. I have an audit table that tracks any changes to the database at the db level. One of the requirements is to track the User Id based on windows login. Is there a way to do this via triggers on the database?
I tried to use USER_NAME(USER_ID()) but all I get is “dbo”
Or should I create a separate stored proc to pass in the user ID from the desktop application to the database? I don’t want to go this route because if anyone changes the db in sql server then I won’t be able to track it.
ORIGINAL_LOGINreturns the name of the login that connected to the instance of SQL ServerSUSER_SNAME()returns the current login nameThe two return the same login name, except if EXECUTE AS is used.