SSIS 2012 将变量从子包传递到父包 [英] SSIS 2012 pass variable from child to parent package

查看:45
本文介绍了SSIS 2012 将变量从子包传递到父包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将子包中的变量值拉到父包中.我不能让它工作.

我可以使用包配置从父级到子级设置变量,但我找不到将子级值放入父级的方法.我尝试使用与以前在子进程中从父进程设置值相同的过程,但它不起作用.

从另一个主题发布的可能解决方案并没有解决它刚刚声明的问题,这可能是不可能的.这篇文章是 2013 年的,很多事情都发生了变化,我想看看现在是否可行(无需将值保存到外部表或类似的东西).

解决方案

这个子包被用在很多地方,其中很多地方没有我试图设置的父变量(它不会存在于父变量).所以上面帖子中的标准脚本不起作用.我希望有一个简单的返回变量值.

以上面的帖子为起点,我更新了 C# 代码以检查我试图在父包中设置的变量是否首先存在(因为它并不总是存在),然后如果存在则设置它.

下面是我想出的代码

<块引用>

//必须首先执行此操作,以便您可以访问变量而无需将其从 SSIS 工具箱传递到脚本任务中//填充变量集合.//这将包括父包变量.变量 vars = null;Dts.VariableDispenser.GetVariables(ref vars);

//检查此变量是否存在,如果存在则将其设置为子变量的值if (Dts.VariableDispenser.Contains("ParentVar") == true){//MessageBox.Show("ParentVariableExists");//锁定 to 和 from 变量.//父变量Dts.VariableDispenser.LockForWrite("User::ParentVar");//子变量Dts.VariableDispenser.LockForRead("User::ChildVar");//显然需要在锁定它们后再次调用 GetVariables.//不知道为什么 - 也许是为了获得一组干净的锁定后值.Dts.VariableDispenser.GetVariables(ref vars);//父变量 = 子变量vars["User::ParentVar"].Value = vars["User::ChildVar"].Value;vars.Unlock();}

I need to pull the value of a variable in a child package to the parent package. I can not get this to work.

I can set variables from parent to child using package configurations, but I cant find a way to get child value into parent. I tried using same process I used to set value from parent in child but it does not work.

The posted possible solution from another topic did not solve the problem it just stated it may not be possible. The post was from 2013 and a lot of things change, I wanted to see if this is possible now (without saving a value to an external table or anything like that).

解决方案

This child package is being used in a lot of spots, many of which would not have the parent variable I am trying to set (it would not exist in the parent variable). So the standard script in the post above would not work. I was hoping for a simple return variable value.

Using the above post as a starting point I updated the C# code to check to see if the variable I am trying to set in the parent package exists first (because it would not always be there), then if so set it.

Below is the code I came up with

        // have to do this FIRST so you can access variable without passing it into the script task from SSIS tool box
        // Populate collection of variables.  
        //This will include parent package variables.
        Variables vars = null;
        Dts.VariableDispenser.GetVariables(ref vars);

        // checks if this variable exists, and if so then will set it to the value of the child variable

        if (Dts.VariableDispenser.Contains("ParentVar") == true)            
        {
            //MessageBox.Show("ParentVariableExists");

            // Lock the to and from variables. 
            // parent variable
            Dts.VariableDispenser.LockForWrite("User::ParentVar");
            // child variable
            Dts.VariableDispenser.LockForRead("User::ChildVar");

            // Apparently need to call GetVariables again after locking them.
            // Not sure why - perhaps to get a clean post-lock set of values.
            Dts.VariableDispenser.GetVariables(ref vars);
            // parentvar = childvar
            vars["User::ParentVar"].Value = vars["User::ChildVar"].Value;

            vars.Unlock();

        }

这篇关于SSIS 2012 将变量从子包传递到父包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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