SSIS 脚本组件无法写入 ReadWriteVariable

发布于 2024-11-30 21:57:59 字数 446 浏览 0 评论 0原文

我在 SQLServer 2008 R2 上的 SSIS 中有一个脚本组件,它需要能够写入读写变量以生成用于平面文件导出的文件名。我创建了一个包级变量来保存文件名,并将平面文件连接设置为使用包含该变量的表达式。

我有一个脚本组件,除其他外,它在执行后方法中动态构建文件名。我已在脚本组件的 ReadWriteVariables 设置中设置了该变量。

如果变量中没有默认值,包将立即失败,因为平面文件连接管理器尝试评估表达式以设置目标文件。所以,我只是输入了一个占位符文件名。

问题是现在它总是使用占位符文件名而不是脚本指定的文件名。确保我可以写入这些变量的最佳方法是什么?我尝试了 Variables.VariableName = "value",我还尝试使用 VariableDispenser 和 this.ReadWriteVariables["VariableName"].value,但它们都没有保留我在脚本中设置的值。

I have a script component in SSIS on SQLServer 2008 R2, that needs to be able to write to a Read-Write variable to produce a file name for a flat file export. I created a package level variable to hold the file name, and set the flat file connection to use an expression containing the variable..

I have a script component that, among other things, builds the file name dynamically in the post execute method. I've set the variable in the ReadWriteVariables setting of the script component.

The package will immediately fail if I don't have a default value in the variable, because the flat file connection manager tries to evaluate the expression to set up the destination file. So, I just put in a placeholder file name.

The problem is that now it always uses the placeholder filename instead of the one that the script specifies. What's the best way to make sure that I can write to those variables? I tried Variables.VariableName = "value", I've also tried using VariableDispenser and this.ReadWriteVariables["VariableName"].value, and none of them are persisting the value I set in the script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离线来电— 2024-12-07 21:58:00

这是一种从数据流任务内可用的脚本组件为包变量赋值的方法。

我尝试锁定脚本任务或脚本组件内的变量,而不是在“属性”对话框中指定它们。我觉得这样更容易维护。

在下面的示例中,我有一个名为 FileName 的包变量,并且在脚本组件C:\Temp\PathChanged嗯>。

我相信脚本组件可能不是操作包变量值(例如文件名)的正确位置,但这又取决于您想要执行的操作。

希望有帮助。

/* Microsoft SQL Server Integration Services Script Component
*  Write scripts using Microsoft Visual C# 2008.
*  ScriptMain is the entry point class of the script.*/

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    public override void PreExecute()
    {
        base.PreExecute();
    }

    public override void PostExecute()
    {
        base.PostExecute();

        IDTSVariables100 varCollection = null;
        this.VariableDispenser.LockForWrite("User::FileName");
        this.VariableDispenser.GetVariables(out varCollection);

        varCollection["User::FileName"].Value = @"C:\Temp\PathChanged";
    }

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
    }
}

脚本组件

Here is one way you can assign value to a package variable from within Script Component available inside Data Flow Task.

I try to lock the variables inside the Script Task or Script Component instead of specifying them on Properties dialog. I feel this is easier to maintain.

In the following example, I have a package variable named FileName and the variable is being assigned with the value C:\Temp\PathChanged inside the Script Component.

I believe that Script Component may not be the right place to manipulate the package variable value such as file name but again that depends on what you are trying to do.

Hope that helps.

/* Microsoft SQL Server Integration Services Script Component
*  Write scripts using Microsoft Visual C# 2008.
*  ScriptMain is the entry point class of the script.*/

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;

[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
    public override void PreExecute()
    {
        base.PreExecute();
    }

    public override void PostExecute()
    {
        base.PostExecute();

        IDTSVariables100 varCollection = null;
        this.VariableDispenser.LockForWrite("User::FileName");
        this.VariableDispenser.GetVariables(out varCollection);

        varCollection["User::FileName"].Value = @"C:\Temp\PathChanged";
    }

    public override void Input0_ProcessInputRow(Input0Buffer Row)
    {
    }
}

Script Component

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文