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

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

问题描述

我是新的在SSIS,工作在一个项目,并尝试访问我的c#代码中我使用的
中的SSIS包变量数据流 - >脚本组件 - >我的C#脚本

$



也尝试过这种方法也无效




b $ b

  IDTSVa​​riables100 varCollection = null; 
this.VariableDispenser.LockForRead(User :: FilePath);
string XlsFile;

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


解决方案

在脚本中访问包变量 / strong>(数据流任务)与在脚本任务中访问包变量不同。对于脚本组件,您需要先打开脚本转换编辑器(右键单击组件并选择编辑...)。在脚本选项卡的自定义属性部分中,您可以在只读或读写的基础上输入(或选择)您希望对脚本可用的属性:

然后,在脚本本身中,变量将作为强类型的属性变量对象:

  //根据需要修改
public override void PreExecute()
{
base.PreExecute();
string thePath = Variables.FilePath;
//做某事...
}

public override void PostExecute()
{
base.PostExecute();
string theNewValue =;
//做某事找出新的值...
Variables.FilePath = theNewValue;
}

public override void Input0_ProcessInputRow(Input0Buffer Row)
{
string thePath = Variables.FilePath;
//在这里做任何需要...
}

注意:如果您需要书写到包变量,则只能在PostExecute()方法中执行。



  IDTSVa​​riables100 varCollection = null; 
this.VariableDispenser.LockForRead(User :: FilePath);
string XlsFile;

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

varCollection 初始化为null,到有效值。因此,任何尝试取消引用都会失败。


i am new in SSIS, working on a project, and trying to access SSIS package variables inside my c# code which i have used in Data Flow -> Script Component - > My c# Script

can anyone help on this ?

also i have tried with which is also not working

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

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

解决方案

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 ...
}

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

Regarding the code snippet:

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

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

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

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

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