What is the purpose of the fireAgain parameter in the Dts.Events.FireInformation method?

When firing Integration Services events from a script, I stumbled a bit about the FireInformation method from the Microsoft.SqlServer.Dts.Tasks.ScriptTask.EventsObjectWrapper Dts property in Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase. The last parameter, fireAgain, is passed by reference. The documentation explains: "True to continue firing, otherwise false." Why pass a parameter by reference? Are there conditions where a method sets to true and requires the caller to repeat the call? If the caller sets the value to false, what are the consequences?

+3


source to share


2 answers


The reason FirstInformation provides a mechanism to suppress further events is cost. Raising events can be costly and given that these messages are by definition informational, it makes sense to allow log providers or configure tasks to stop the event from being generated.

From IDTSComponentEvents.FireInformation Method



Since firing an event can be costly, the runtime mechanism provides a mechanism to suppress events that you are not interested in. Each event triggering method has a FireAgain parameter. If this variable is false, after the method returns, the caller will not fire this event again for the duration of the current execution.

+1


source


Like the comments, I think the event method documentation is inconsistent at best and definitely confusing. I think billinkc is pointing us in an interesting direction with a dedicated logging provider. Also of interest is the documentation on handling events programmatically . Although the samples don't specifically state how callers should handle fireAgain parameters or return values. I believe that we should respect the value for all subsequent attempts to fire an event of types: custom, error, information and progress. Although stated in the documentation, "Each event fade method has a FireAgain parameter." It just isn't true. FireWarning does not provide a return or parameter for FireAgain.

In your custom ScriptTask, you can implement wrapper methods to handle the FireAgain parameter or return value.



private bool shouldFireCustomEvent = true;
private void TaskLevelFireCustomEvent(string eventName, string eventText, ref object[] arguments, string subComponent)
{
    if (!shouldFireCustomEvent) { return; }
    Dts.Events.FireCustomEvent(eventName, eventText, ref arguments, subComponent, ref shouldFireCustomEvent);
}

private bool shouldFireError = true;
private void TaskLevelFireError(int errorCode, string subComponent, string description, string helpFile, int helpContext)
{
    if (!shouldFireError) { return; }
    this.shouldFireError = Dts.Events.FireError(errorCode, subComponent, description, helpFile, helpContext);
}

private bool shouldFireInformation = true;
private void TaskLevelFireInformation(int informationCode, string subComponent, string description, string helpFile, int helpContext)
{
    if (!shouldFireInformation) { return; }
    Dts.Events.FireInformation(informationCode, subComponent, description, helpFile, helpContext, ref shouldFireInformation);
}

private bool shouldFireProgress = true;
private void TaskLevelFireProgress(string progressDescription, int percentComplete, int progressCountLow, int progressCountHigh, string subComponent)
{
    if (!shouldFireProgress) { return; }
    Dts.Events.FireProgress(progressDescription, percentComplete, progressCountLow, progressCountHigh, subComponent, ref shouldFireProgress);
}

private void TaskLevelFireWarning(int warningCode, string subComponent, string description, string helpFile, int helpContext)
{
    Dts.Events.FireWarning(warningCode, subComponent, description, helpFile, helpContext);
}

      

In my few tests, I have not seen enabled log providers to use the fireAgain parameter, and it would be interesting to see a case where the return value is actually incorrect.

0


source







All Articles