Ask the Expert

What is the best way to get to connection information inside a trigger?

What is the best way to get to connection information inside a trigger? We log on to our app with a specific username and to SQL Server using a global username. Inside triggers, we want to update a "last_modified_by" column with the specific username. The only way I can see of doing this is to have a table with suser_sid, specific_user_name and date/time. I would insert a row at logon and then select that row from inside the trigger. Do you know of a better way?

    Requires Free Membership to View

I don't think there are very many solutions for you that will be quick, easy and painless. The first thought that comes to mind is to use the SET CONTEXT_INFO command to set the specific username for each user that logs in for the duration of their session. You can then query the context_info column of sysprocesses from your trigger to record any changes to your database the specific user makes. I hope this helps!

This was first published in August 2005

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: