【问题标题】:Initialize SSIS Variable with Package Configuration使用包配置初始化 SSIS 变量
【发布时间】:2016-03-29 19:39:27
【问题描述】:

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

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

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

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

这些是当前的包配置:

这是来自“变量”窗口:

这是脚本任务的代码:

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

【问题讨论】:

    标签: vb.net ssis visual-studio-2005 bids


    【解决方案1】:

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

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

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

    \Package.Variables[User::VariableName].Properties[Value]

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

    【讨论】:

      猜你喜欢
      • 2014-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多