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

时间:2018-09-11 14:21:50

标签: vb.net ssis script-task

我正在尝试使用Visual Basic在SSIS中以编程方式创建“执行打包任务”。但是我无法使其与UseProjectReference = True一起使用。程序包不会失败,但是什么也不会发生。我还缺少其他财产吗?这是代码

"/api/v1.0/Subscriber/2727272727"

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

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

1 个答案:

答案 0 :(得分:0)

作为一种解决方法,我将包保存到磁盘上,项目引用设置为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)