SSIS脚本任务获取所有变量名称和值

问题描述 投票:0回答:1

我需要解析我的ssis包中的所有用户变量。截至目前,我能够获取包中所有变量的名称和值。我需要获取名称和值并将它们转储到表中。截至目前,我可以通过消息框显示名称和值,但我似乎无法弄清楚,如何在脚本任务上我可以将这些值转储到表中。任何帮助将不胜感激。

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
//using System;
////using Microsoft.SqlServer.Dts.Runtime;
namespace ST_81ec2398155247148a7dad513f3be99d.csproj
{
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
    {

        #region VSTA generated code
        enum ScriptResults
        {
            Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
            Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
        };
        #endregion

    public void Main()
    {


        Microsoft.SqlServer.Dts.Runtime.Application app = new Microsoft.SqlServer.Dts.Runtime.Application();
        // Load a sample package that contains a variable that sets the file name.
        Package pkg = app.LoadPackage(
          @"C:\PackagePath\" +
          @"Template0719.dtsx",
          null);
        Variables pkgVars = pkg.Variables;
        foreach (Variable pkgVar in pkgVars)
        {

            MessageBox.Show(pkgVar.Name);
            MessageBox.Show(pkgVar.Value.ToString());
        }
        Console.Read();
    }
    }

    }
c# sql-server-2008 ssis custom-component
1个回答
0
投票

由于您知道如何获取变量列表,因此可以创建数据源脚本组件。

© www.soinside.com 2019 - 2024. All rights reserved.