K2BAudit SQLServer Configuration

IMPORTANT: This page applies to K2BAudit version 5.1 and earlier ones. Newer versions do not require these settings.

Introduction

This page contains configuration instructions to use K2BAudit with SQLServer. These instructions steps must be followed whenever a new environment using this DBMS is created. Some of them also apply when deploying an application with K2BAudit that uses SQLServer.

Step 1 - Configure the K2BAudit datastore

In your KB, a new DataStore called “K2BAudit” will appear after executing the “Initialize Audit” action. This DataStore is the location where the audit logs are stored. This DataStore must be configured to connect to the K2BAuditAnalyzer database.

If you are configuring the DataStore in the GeneXus IDE, you can find it in the DataStores section of your environment’s configuration.

K2BAuditDataStoreSQLServer
K2BAudit DataStore

If you are configuring the DataStore in the generated application, you must use the configuration file.

Step 2 - Application user retrieval configuration

When an operation is audited, the user that is currently using the application is saved together with the operation values.

In order to get the application user, K2BAudit uses a procedure that is configured in the “After connect” property in the generator. The procedure that should be used in SQLServer environments is the “K2BSaveAuditUserSQLServer”.

K2BAuditAfterConnectProcedures
K2BAudit After connect procedures

In this procedure there is a section delimited by comments with the text “Set User Code”. The developer must update this section’s contents to load the correct User Code in the &User variable. The default implementation loads the user code from the application context.

K2BAuditAfterConnectSetUserCodeSection
Set User Code section

After updating the procedure’s code, the “After connect” property in the model must be updated to reference this procedure.

K2BAuditAfterConnectPropertySQLServer
After connect property

Step 3 - LUW information configuration

When using K2BAudit with an SQLServer database, it is possible to store information about which LUW an operation was executed. For each LUW, K2BAudit stores all the operations performed in audited tables, the date and time when the commit command was executed, and the GeneXus object that executed the commit command.

In order to enable this feature, set the "Before commit" property in the generator to "K2BBeforeCommitSQLServer".

K2BAuditBeforeCommitPropertySQLServer
Before connect property

Step 4 - SQLServer configuration

4.1 - User permissions

The application SQLServer user must have the "Sysadmin" server role to create the triggers in the database. Use SQL Server Management studio to grant that role to the user.

K2BAuditSQLServerSysadminRole
SQLServer configuration

Also if you use the LUW funcionality (STEP 3) the sys.dm_tran_ application users needs to have the VIEW SERVER STATE permission on the database. The LUW funcionality selects a record from the sys.dm_tran_current_transaction, so VIEW SERVER STATE permissions must be granted to the user. In order to grant the permission please see the GRANT SERVER permissions documentation on SQLServer.

4.2 - Load the K2BAudit stored procedures

Triggers generated by K2BAudit need to call a stored procedure. In order for the triggers to work you must create the stored procedure. To do so,run the script located in <GX_INSTALL_DIR>\Packages\K2BTools\Audit\SQLServer\K2BAuditProcedures.sql. Execute this script inside the application's database.

If you skip this step the following error messasge will be shown when adding a record to an audited table:

Could not find stored procedure dbo.K2BParseContextInfo. The statement has been terminated.