/* In order to obtain the "APPLICATION USER" (for applications that have a custom authentication schema) and "Host IP ADDRESS" audit info, your application must call this stored procedure after connect to the DBMS to set this audit info at session level. In this situation, your application is responsible to pass correctly the application user and ip stored procedure parameters. */ if exists (select * from dbo.sysobjects where upper(name) = 'AUDITDATABASE_SETSESSIONINFO' and OBJECTPROPERTY(id, N'IsProcedure') = 1) drop procedure [dbo].[AuditDatabase_SetSessionInfo] GO CREATE PROCEDURE [dbo].[AuditDatabase_SetSessionInfo] @ApplicationUser VARCHAR(50), @LogicalAddress VARCHAR(30) AS Begin declare @field_terminator varchar(3) declare @varbin varbinary(128) declare @auditdatabase_info varchar(128) set @field_terminator = '///' IF len(@ApplicationUser) > 0 set @auditdatabase_info = 'APPLICATION_USER=' + RTRIM (@ApplicationUser) + @field_terminator if len(@LogicalAddress) > 0 set @auditdatabase_info = @auditdatabase_info + 'LOGICAL_ADDRESS=' + RTRIM(@LogicalAddress) + @field_terminator set @varbin=CAST( @auditdatabase_info AS varbinary(128) ) set context_info @varbin End GO