Evaluating an expression programmatically

Main question

Is there a method that I'm missing for evaluating an expression in SSIS?

Background

I commit a lot of packages programmatically to fit our standards. In its simplest form, suppose I create a new variable and assign expression . It works great.

variable with expression

If I clicked on the ellipses and then click on “Calculate Expression” in the dialog box that appears, I can see that my formula is being evaluated syntactically correctly and will generate the expected value logically. How is the assessment?

Evaluate Expression

"OK" , .Value . . , , BIDS/SSDT. , variable.Value = MAGIC;, 101.

, , , . , . Execute SQL Task, , , ( ). , , , ... , .

/// <summary>
/// Create a simple package with a variable that has an expression to figure
/// out how to evaulate the resulting value.
/// </summary>
static void ExpressionPOC()
{
    Microsoft.SqlServer.Dts.Runtime.Package p = new Microsoft.SqlServer.Dts.Runtime.Package();
    Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
    p.Name = "ProofOfConcept";
    Microsoft.SqlServer.Dts.Runtime.Variable v = null;
    // This creates a simple variable of type string with an initial value of blank string
    v = p.Variables.Add("ContrivedExample", false, "User", string.Empty);
    v.Expression = @"""My package is named "" + @[System::PackageName]";
    // Looking for something here to 
    //v.Value = v.Expression.EvaluatePrettyPlease();
    app.SaveToXml(@"C:\Users\bfellows\Documents\Visual Studio 2012\Projects\Demo\Demo\testVariable.dtsx", p, null);
}
+5
1

, - . SQL Server 2012 BIDSHelper , 2 .

  • .
  • , , EvaluateAsExpression = true. .

//v.Value = v.Expression.EvaluatePrettyPlease();
// The missing EvaluatePrettyPlease method is the property EvaluateAsExpression
// By setting this property, the expressions actually evaluate
// go figure
v.EvaluateAsExpression = true;
+4

All Articles