Hi,
I'm inserting/updating audit information in my SQL Server tables, and I need the ability to use functions such as SUSER_SNAME(), APP_NAME() and HOST_NAME().
For example, some of my tables' columns are:
_InsertedBy varchar(64) NULL,
_UpdatedBy varchar(64) NULL,
_InsertingApplication varchar(64) NULL,
_UpdatingApplication varchar(64) NULL,
_InsertingMachine varchar(64) NULL,
_UpdatingMachine varchar(64) NULL,
and I need to do either
UPDATE my_table
SET [...],
_UpdatedBy = SUSER_SNAME(),
_UpdatingApplication = APP_NAME(),
_UpdatingMachine = HOST_NAME()
WHERE [...]
Or
INSERT INTO my_table (
[...],
_InsertedBy,
_InsertingApplication,
_InsertingMachine )
VALUES(
[...],
SUSER_SNAME(),
APP_NAME(),
HOST_NAME() )
Depending if I'm doing an update or an insert...
Problem is that those 3 functions I mention do not seem to be supported, as when I save my entity, the actual "SUSER_SNAME()" string is saved, but not the actual username! Not good!
I can't use a trigger obviously (the DBA would not let me anyway!), so the only workaround I can see is to capture the actual value of each function by calling a stored procedure that will wrap those functions. Ugly!!!