【问题标题】:SSIS - Programmatically Execute Package Task Using VBSSIS - 使用 VB 以编程方式执行包任务
【发布时间】:2023-04-09 19:09:02
【问题描述】:

我正在尝试使用 Visual Basic 在 SSIS 中以编程方式创建“执行包任务”。但是我不能让它与 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

【问题讨论】:

    标签: vb.net ssis script-task


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多