Setting Microsoft SQL's Context_Info
In this recipe, we will show you how to use Microsoft SQL Server's Context_Info to provide the current username to your audit triggers.
Getting ready
Complete the previous recipe, Generating trigger-based auditing
Download
Ninject.dllandCommonServiceLocator.NinjectAdapter.dllfrom the Ninject project at http://ninject.orgDownload
Microsoft.Practices.ServiceLocation.dllfrom the Microsoft patterns and practices team available at http://commonservicelocator.codeplex.com/
How to do it…
Add a reference to
Ninject.dll,CommonServiceLocator.NinjectAdapter.dllandMicrosoft.Practices.ServiceLocation.dll.Add the following
IAuditColumnSourceimplementation:public class CtxAuditColumnSource : IAuditColumnSource { public IEnumerable<AuditColumn> GetAuditColumns(Table dataTable) { var userStamp = new AuditColumn() { Name = "AuditUser", Value = new SimpleValue() { TypeName = NHibernateUtil.String.Name }, ...