简体   繁体   中英

Get windows user from connection string

For a trigger in SQL Server 2008R2 I need to know the user who inserted, updated or deleted the record.

As different users log in with the same connection string I do not know who is really logged in to the server (I use SQL authentication with the same UID and I grant access through the Access database!!).

I would like if possible to add a variable to the connection string such as Application Name=myrealusername but it seems that from Access VBA I cannot add this Parameter.

Does anyone know how to retrieve the real username who's logged in to pass the username to the trigger?

You could try recording the HOST_NAME() to capture the instance the query was executed from. If every user has it's own PC, it's probably one of your best guesses if you don't plan on using Windows Authentication.

More details: HOST_NAME() MSDN Documentation

Obviously the only real solution would be to use Windows Authentication.

您可以使用 Windows 身份验证并尝试使用

select suser_name()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM