Bruno Gomes Bruno Gomes - 4 months ago 33
C# Question

SSIS Custom transformation receive variable

I am creating a custom transformation in C# to be used in SSIS. I have already been able creating and adding the custom component and receive and alter data from a db source but I need more data to register in a log table. This data can only be passed with variables but I can't find a good explanation of how to add a

readonlyvariable
to my component.

I have tried to use IDTSVariable100 and VariableDispenser but I can't make sense of how to.

public override void ProvideComponentProperties()
{
base.ProvideComponentProperties();
base.RemoveAllInputsOutputsAndCustomProperties();
VariableDispenser varDispenser = this.VariableDispenser();

IDTSVariable100 vr = this.VariableDispenser.GetVariables();
IDTSInput100 input = this.ComponentMetaData.InputCollection.New();
input.Name = "Input_B";

IDTSOutput100 output=this.ComponentMetaData.OutputCollection.New();
output.Name = "Output_B";

// the output is synchronous with the input
output.SynchronousInputID = input.ID;

}


Basically i want to define
readonlyvariables
that I can alter the value before my custom component runs like the original "script component" has.

Answer

Well i researched a bit more and stumbled on a answer: It seems that to access the SSIS public variables we have to get them with code on the ProcessInput Method:

var dimSrcId ="";

IDTSVariables100 variables = null;

this.VariableDispenser.LockForRead("User::dimSrcId");

this.VariableDispenser.GetVariables(out variables);

dimSrcId = variables["User::dimSrcId"].Value.ToString();

variables.Unlock();

By using the VariableDispenser.LockForRead() we're capable of searching for our variables and access there value.