Version: SQL Anywhere 16.0.0.2127 Scenario:
Issue: A call to function User_Id() inside this trigger is returning the previous user 'AA' even though user 'BB' made the UPDATE. This seems like a SQL Anywhere defect to me. Query inside the trigger: SELECT user_name FROM sysuser WHERE user_id = User_Id() |
Just a hint: The name of the current user is available without a query, just use the user_name() builtin function or the "current user" special value... That being said, you are running a quite old v16 build. There have been several fixes to connection pooling, see here. So a newer build might be worthwhile to try... Thanks for your response Volker. I will try CURRENT_USER and USER_NAME() in the trigger.
(22 Jan '21, 16:21)
chinmaydixit
Replies hidden
Well, I would not expect a different result compared to your query, it's just more efficient and shorter... What do you need that user name within the trigger? In case you just want to log the user doing the update, the DEFAULT LAST USER can do so without needing a trigger...
(22 Jan '21, 16:47)
Volker Barth
The trigger is used for audit logging (log the user who did the update) and the update is done from the front end .NET app.
(25 Jan '21, 09:10)
chinmaydixit
Using USER_NAME() in place of USER_Id() actually worked !!! USER_NAME() returns the correct user inside the trigger in the scenario where the user id was switched. I am wondering how the implementation would be different within Sybase. Thank you so much Volker !!! You made my day. You are a rock star :-)
(25 Jan '21, 14:02)
chinmaydixit
1
LOL, I'm glad my expectation was wrong –even if I don't understand why it does make a difference...:)
(26 Jan '21, 03:16)
Volker Barth
|