Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

capture web application username and other session info in sql trigger Expand / Collapse
Author
Message
Posted Sunday, July 28, 2013 4:36 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Sunday, July 28, 2013 4:35 AM
Points: 1, Visits: 0
Hi,

I have created a trigger to audit changes to table rows from my web application. My web application is using a single db user to do updates to the database. However, many different users can log in to the website and do the updates and inserts. Therefore, the db user will always be same but web users will be different

I want to have some way to capture the logged in user to the website who is making the changes to the rows so that I can audit the changes along with the web user that is making the changes.

Can someone please guide me how can I capture the web session in my sql trigger so that I know who is making the changes. Can I configure the web.config file so that the session info is also passed on to the sql server trigger or if there is some other way, please let me know

Regards

Arif
Post #1478343
Posted Sunday, July 28, 2013 1:56 PM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Sunday, September 29, 2013 1:24 AM
Points: 429, Visits: 1,721
syedshah (7/28/2013)
Hi,

I have created a trigger to audit changes to table rows from my web application. My web application is using a single db user to do updates to the database. However, many different users can log in to the website and do the updates and inserts. Therefore, the db user will always be same but web users will be different

I want to have some way to capture the logged in user to the website who is making the changes to the rows so that I can audit the changes along with the web user that is making the changes.

Can someone please guide me how can I capture the web session in my sql trigger so that I know who is making the changes. Can I configure the web.config file so that the session info is also passed on to the sql server trigger or if there is some other way, please let me know

Regards

Arif

Use any of a number of system functions...go to Programmability->Functions->System Functions. One of these is probably what you are looking for.


SELECT Current_User
SELECT App_Name()
SELECT Host_Name()
SELECT Session_User
SELECT System_User


 
Post #1478402
Posted Sunday, July 28, 2013 2:59 PM


Right there with Babe

Right there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with BabeRight there with Babe

Group: General Forum Members
Last Login: Thursday, April 17, 2014 4:43 AM
Points: 756, Visits: 631
This is what SET CONTEXT_INFO and the function context_info() is for.

See this section in an article on my web site for more details:
http://www.sommarskog.se/grantperm.html#context_info

(You only have to read this section, and you don't have to continue with the section "Using DDL triggers to stop all this".)


Erland Sommarskog, SQL Server MVP, www.sommarskog.se
Post #1478408
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse