如何访问脚本组件内的 ssis 包变量 [英] How to access ssis package variables inside script component

查看:38
本文介绍了如何访问脚本组件内的 ssis 包变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何访问我在数据流中使用的 C# 代码中的变量 -> 脚本组件 -> 带有 SSIS 包的 c# 脚本?

How can I access variables inside my C# code which I've used in Data Flow -> Script Component - > My c# Script with my SSIS package?

我试过,它也不起作用

IDTSVariables100 varCollection = null;
this.VariableDispenser.LockForRead("User::FilePath");
string XlsFile;

XlsFile = varCollection["User::FilePath"].Value.ToString();

推荐答案

在脚本组件(数据流任务)中访问包变量与在脚本中访问包变量不同<强>任务.对于脚本组件,您首先需要打开 脚本转换编辑器(右键单击组件并选择编辑...").在脚本"选项卡的自定义属性"部分,您可以输入(或选择)要在只读或读写基础上提供给脚本的属性:然后,在脚本本身中,变量将作为 Variables 对象的强类型属性可用:

Accessing package variables in a Script Component (of a Data Flow Task) is not the same as accessing package variables in a Script Task. For a Script Component, you first need to open the Script Transformation Editor (right-click on the component and select "Edit..."). In the Custom Properties section of the Script tab, you can enter (or select) the properties you want to make available to the script, either on a read-only or read-write basis: Then, within the script itself, the variables will be available as strongly-typed properties of the Variables object:

// Modify as necessary
public override void PreExecute()
{
    base.PreExecute();
    string thePath = Variables.FilePath;
    // Do something ...
}

public override void PostExecute()
{
    base.PostExecute();
    string theNewValue = "";
    // Do something to figure out the new value...
    Variables.FilePath = theNewValue;
}

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
    string thePath = Variables.FilePath;
    // Do whatever needs doing here ...
}

一个重要的警告:如果您需要写入到包变量,则只能在 PostExecute() 方法中进行.

One important caveat: if you need to write to a package variable, you can only do so in the PostExecute() method.

关于代码片段:

IDTSVariables100 varCollection = null;
this.VariableDispenser.LockForRead("User::FilePath");
string XlsFile;

XlsFile = varCollection["User::FilePath"].Value.ToString();

varCollection 被初始化为 null 并且从不设置为有效值.因此,任何取消引用它的尝试都将失败.

varCollection is initialized to null and never set to a valid value. Thus, any attempt to dereference it will fail.

这篇关于如何访问脚本组件内的 ssis 包变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆