I have a multi-user application which makes various calls to SQL to alter values in various tables. Some of those tables have triggers on them to audit changes. I have code in the trigger that attempts to match the SPID value, as returned by @@SPID, with SPID values stored by users as they register for DB access (log in).
However, my testing shows that, at least some of the time, the SPID at the time of the trigger running is not the same as the SPID previously saved. How can i get the SPID of the connection that made the DB change that caused the trigger to run? Or if not the SPID, some value that fairly reliably identifies the currently active SQL connection that made the change?
This is for medium-term debugging, not intended to be part of permanent production code, but must run on a live system for days to weeks.