Private Sub SqlDataSource2_Updating(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource2.Updating SqlDataSource2.UpdateCommand = "DECLARE @ContextInfo varbinary(128);SELECT @ContextInfo = cast( @User AS varbinary(128) );SET CONTEXT_INFO @ContextInfo;UPDATE [TIP_Projects] SET [Notes] = @Notes, [GuardRails] = @GuardRails, [UtilityRelocation] = @UtilityRelocation, [PvmtPreservation] = @PvmtPreservation, [ADAEnhancement] = @ADAEnhancement, [Landscape] = @Landscape, [BikeRack] = @BikeRack, [Art] = @Art, [MultiUsePath] = @MultiUsePath, [Curbs] = @Curbs, [StreetLighting] = @StreetLighting, [PedLighting] = @PedLighting, [Rightofway] = @Rightofway, [Median] = @Median, [Signing] = @Signing, [Drainage] = @Drainage, [Overpass] = @Overpass, [Underpass] = @Underpass, [Wildlife] = @Wildlife, [Signals] = @Signals, [Cameras] = @Cameras, [Culvert] = @Culvert, [Bridge] = @Bridge, [Striping] = @Striping, [TurnLanes] = @TurnLanes, [BusPullout] = @BusPullout, [Soundwall] = @Soundwall, [RubberAsph] = @RubberAsph, [System] = @System, [SubSystem] = @SubSystem, [MapStyle] = @MapStyle, [GeoArea] = @GeoArea, [NewBikeLanes] = @NewBikeLanes, [NewSidewalks] = @NewSidewalks, [Modeled] = @Modeled, [LongDesc] = @LongDesc, [Capacity]=@Capacity, [Operations]=@Operations, [Enhancement]=@Enhancement, [Safety]=@Safety, [SR2S]=@SR2S, [Procurement]=@Procurement, [TrafficCalming]=@TrafficCalming WHERE [KeyId] = @KeyId" SqlDataSource2.UpdateParameters.Add("@User", DbType.String, "donf") End SubThis executes and the save works OK both in the edited table and the audit table.
SELECT @UserName = CAST(CONTEXT_INFO() AS VARCHAR(128)), @UpdateDate = convert(varchar(8), getdate(), 112) + ' ' + convert(varchar(12), getdate(), 114)This saved the edits OK but the trigger did not save the audit record.
SELECT @UserName = CAST(CONTEXT_INFO() AS VARCHAR(128)), @UpdateDate = convert(varchar(8), getdate(), 112) + ' ' + convert(varchar(12), getdate(), 114) SELECT @UserName = 'Donf'And this works OK. So the failure must be that the code sending the username to Context_Info or the code to read it back out needs improvement.