SSIS - 使用 VB 以编程方式执行包任务

SSIS - Programmatically Execute Package Task Using VB

我正在尝试使用 Visual Basic 在 SSIS 中以编程方式创建 'Excute Package Task'。但是我无法让它与 UseProjectReference = True 一起使用。该包没有失败,但没有任何反应。我错过了其他一些 属性 吗?这是代码

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

下面的代码可以成功地从文件系统调用包,但是正如我提到的,我需要从项目中调用包。

Public Sub Main()
    Dim ExecResult As DTSExecResult = DTSExecResult.Failure
    Dim SIFISO_app As Application = New Application
    Dim p As Package = New Package
    Dim cm_DES As ConnectionManager = p.Connections.Add("FILE")
    cm_DES.Name = "local_pkg"
    cm_DES.ConnectionString = String.Format("C:\Test.dtsx")
    Dim exec As Executable = p.Executables.Add("STOCK:ExecutePackageTask")
    Dim th As TaskHost = CType(exec, TaskHost)
    th.Properties("Name").SetValue(th, "Execute selectSIFISO Package")
    th.Properties("Description").SetValue(th, "Execute selectSIFISO Package")
    th.Properties("Connection").SetValue(th, "local_pkg")
    th.Properties("ExecuteOutOfProcess").SetValue(th, "False")
    ExecResult = p.Execute()
    p.Dispose()
    Dts.TaskResult = ScriptResults.Success
End Sub

作为解决方法,我将项目引用设置为 true 并将包保存到磁盘,然后使用以下代码将包加载到 SSISDB。不完全是我想要的,但按我想要的方式工作。

        ' Before deploying packages, make sure the destination project exists in SSISDB.  
    Dim connectionString As String = "Data Source=localhost;Integrated Security=True;MultipleActiveResultSets=false"
    Dim catalogName As String = "SSISDB"
    Dim folderName As String = "Test"
    Dim projectName As String = "Test"
    ' Get the folder instance.  
    Dim sc As SqlConnection = New SqlConnection(connectionString)
    Dim store As New Microsoft.SqlServer.Management.IntegrationServices.IntegrationServices(sc)
    Dim folder As CatalogFolder = store.Catalogs(catalogName).Folders(folderName)
    ' Key is package name without extension and value is package binaries.  
    Dim packageDict As New Dictionary(Of String, String)()

    Dim packageData As String
    packageData = My.Computer.FileSystem.ReadAllText("C:\Package7.dtsx")
    packageDict.Add("Package7", packageData)

    ' Deploy package to the destination project.  
    folder.DeployPackages(projectName, packageDict)