locked
creating execute package task programmatically (VB) RRS feed

  • Question

  • Hi,

    I'm trying to programmatically create an 'Excute Package Task' in SSIS using Visual Basic. However I can't get it to work with UseProjectReference = True. The package doesnt fail but nothing happens. I assume it's because the package doesnt know it's part of the project. If I save the package and then open it, it creates perfectly.

    Also how do I include the parameter bindings for a child package?? (from below link)

    https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2012/jj723090(v%3dsql.110)

    Public Sub Main()
        Dim ExecResult As DTSExecResult = DTSExecResult.Failure
        Dim p As Package = New Package       
        Dim exec As Executable = p.Executables.Add("STOCK:ExecutePackageTask")
        Dim th As TaskHost = CType(exec, TaskHost)
        th.Properties("Name").SetValue(th, "Execute Package")
        th.Properties("Description").SetValue(th, "Execute Package")
        th.Properties("UseProjectReference").SetValue(th, "True")
        th.Properties("PackageName").SetValue(th, "Test.dtsx")
        th.Properties("ExecuteOutOfProcess").SetValue(th, "False")    
        ExecResult = p.Execute()
        p.Dispose() 
        Dts.TaskResult = ScriptResults.Success
    End Sub

    Friday, September 14, 2018 10:50 AM

Answers

  • What happens if you cast the InnerObject of TaskHost to ExecutePackageTask (in the Microsoft.SqlServer.Dts.Tasks.ExecutePackageTask namespace) and then assign properties to that cast object?

    If you are troubleshooting, create your package and compare the incorrect package XML to a correct package XML; this should give you what properties are missing.

    For parameter bindings, call the Add method on your executepackagetask's ParameterAssignments. This will give you an IDTSParameterAssignment object. Then for this object, you can set the BindedVariableOrParameterName and ParameterName properties.

    Take a look at https://github.com/samskolli/Pegasus/blob/master/Pegasus.DtsWrapper/ControlFlowTasks/ISExecutePackageTask.cs for how I did it (using C# though).

    • Marked as answer by kiwiNspain Monday, September 17, 2018 3:31 PM
    Friday, September 14, 2018 12:31 PM

All replies