I am programmatically generating and executing SSIS packages using C# and SQL Server 2012. The generated packages each contain one Data Flow Task with a Flat File Source for reading CSVs, and an OLE DB Destination connected to SQL Server. In between them is a Row Count component with a SSIS Variable hooked up.
After package execution ends, I want to get the value from the Row Count back to my calling application.
It seems that simply creating the variable & Row Count in code as follows:
[...]
// Row count: Create a package variable to store the row count value
var ssisRowCountVariable = package.Variables.Add("MySsisVar", false, "User", 0);
// Row count: Create Row component
IDTSComponentMetaData100 componentRowCount = dataFlowTask.ComponentMetaDataCollection.New();
componentRowCount.Name = "RowCount";
componentRowCount.ComponentClassID = "DTSTransform.RowCount.4";
// Row count: Get row count design-time instance, and initialize component
CManagedComponentWrapper instanceRowCount = componentRowCount.Instantiate();
instanceRowCount.ProvideComponentProperties();
// Row count: Set the variable name property
instanceRowCount.SetComponentProperty("VariableName", "User::MySsisVar");
// Hooking up pipeline Paths
[...]
// Execute package
package.Execute()
and then trying to read the value after package execution:
int Rows = Convert.ToInt32(ssisRowCountVariable.Value);
does not work.
How can I get the value of the Row Count component back to the calling application?