Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 capture application login in sql server trigger

Author  Topic 

safderalimd
Starting Member

32 Posts

Posted - 2010-05-11 : 14:11:53
Is it possible to capture application user in delete trigger?

We are trying to use sql server delete trigger to audit physical deletes issued from java application. My problem is how can I capture applicaiton deleted by user in sql trigger???

malpashaa
Constraint Violating Yak Guru

264 Posts

Posted - 2010-05-11 : 14:31:19
If you want the user name then use:

SELECT USER_NAME()

But if you want login name then use:

SELECT SUSER_NAME()
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-11 : 14:44:33
If the application is using application security, then it isn't possible to capture the info from the trigger. From SQL Server, we can only see the user name or login name that is being used for the SQL connection. You would need to include the application user in the data in order to see it in the trigger.

But this only applies if you are using application security. Are the application users just a row in a table or are they actually distinct SQL users?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

safderalimd
Starting Member

32 Posts

Posted - 2010-05-11 : 15:02:36
Application users are just a row in a table and application uses common sql login for all connections.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-11 : 15:04:34
There's no way to get this information in SQL Server unless you include the info in the data change.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

safderalimd
Starting Member

32 Posts

Posted - 2010-05-12 : 08:57:34
Thaks for your response.

I guess there are lot of professionals like me who had same issue and I wonder how they are handling it?

SQL server has come long way and I hope they will solve this issue by providing some sort of attributes to SQL threads coming in from external applications.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-12 : 12:39:30
This isn't something SQL Server can ever provide, or any other database software. How will any database software know what user is logged into your application when the application is using one generic account to login into the database?

You handle this by providing the application userid in the DML change row.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -