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

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

问题描述

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



任何人都可以在帮助呢?



此外,我曾尝试与这也没有工作。

  IDTSVa​​riables100 varCollection = NULL; 
this.VariableDispenser.LockForRead(用户::文件路径);
串XlsFile;

XlsFile = varCollection [用户::文件路径] Value.ToString();


解决方案

访问包变量在脚本中的组件(数据流任务)是不一样的剧本工作<访问包变量/ STRONG>。对于一个脚本组件,您首先需要打开脚本转换编辑器(在组件上单击鼠标右键并选择Edit ...)。在脚本选项卡中的自定​​义属性部分,您可以输入(或选择),你要提供给脚本的性能,无论是在只读或读写的基础:

的屏幕截图然后,脚本本身,变量将是可以作为强类型的属性变量对象:

  //根据需要修改
公共覆盖无效PreExecute()
{
base.PreExecute();
串thePath = Variables.FilePath;
//做某事
}

公共覆盖无效PostExecute()
{
base.PostExecute();
串theNewValue =;
//做一些事情弄清楚了新的价值...
Variables.FilePath = theNewValue;
}

公共覆盖无效Input0_ProcessInputRow(Input0Buffer行)
{
串thePath = Variables.FilePath;
//什么就做什么需要在这里做...
}



一个重要警告:如果您需要的,以包变量,你只能做这样的PostExecute()方法。



关于代码片段

  IDTSVa​​riables100 varCollection = NULL; 
this.VariableDispenser.LockForRead(用户::文件路径);
串XlsFile;

XlsFile = varCollection [用户::文件路径] 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天全站免登陆