使用包配置初始化 SSIS 变量

Initialize SSIS Variable with Package Configuration

在 BIDS (Microsoft Business Intelligence Development Studio) 中,如何通过包配置初始化变量?我们在使用用户变量的包中有一个脚本任务。用户变量是硬编码的。我们想让脚本任务可配置。我们有一个 SQL 服务器包配置 table 用于存储包配置。

我们要在脚本任务代码中初始化变量还是可以在变量中完成table?

如果变量是 VariableName 并且包配置的配置名称是 "Configuration Name",语法是什么?

此外,用包配置值初始化变量是否有意义,还是直接使用包配置会更好?

这些是当前的包配置:

这是来自变量window:

这是脚本任务中的代码:

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.IO

Public Class ScriptMain

    ' The execution engine calls this method when the task executes.
    ' To access the object model, use the Dts object. Connections, variables, events,
    ' and logging features are available as static members of the Dts class.
    ' Before returning from this method, set the value of Dts.TaskResult to indicate success or failure.
    ' 
    ' To open Code and Text Editor Help, press F1.
    ' To open Object Browser, press Ctrl+Alt+J.

    Public Sub Main()
        '
        ' Add your code here
        '
        Dim fileName As String

        fileName = CStr(Dts.Variables("User::TrialBalanceReportDirectory").Value) + _
                CStr(Dts.Variables("User::Slash").Value) + _
                CStr(Dts.Variables("User::TrialBalanceReportFile").Value)

        'MsgBox(fileName)

        Dts.Variables("TrialBalanceReportExists").Value = File.Exists(fileName)
        Dts.TaskResult = Dts.Results.Success
    End Sub

End Class

谢谢!

michaelc35

通常直接配置目标 属性 比在两者之间使用变量更清晰。

但是由于您是从脚本任务中引用值,我看不出该脚本任务可以直接访问配置值的方法,而不是通过通过 变量。 (代码中可能有一种方法,我不知道但如果有人发布它会感兴趣阅读)。

从配置中设置变量值的语法是:

\Package.Variables[用户::变量名].属性[值]

(显然,将 VariableName 替换为您的变量名称)。此值指定配置值应 "poked" 到包中的位置。在我的配置 table(使用 SSIS2008)中,它位于 PackagePath 列中。您要分配给变量的值然后进入 ConfiguredValue 列。