Need support for SUSER_SNAME(), APP_NAME() and HOST_NAME()

Posts   
 
    
lionel
User
Posts: 1
Joined: 15-Jun-2006
# Posted on: 15-Jun-2006 22:00:19   

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!confused

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!!!cry

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Jun-2006 08:42:54   

You should implement IExpression as in the following thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3829