Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法读取ssis中的对象变量_Ssis - Fatal编程技术网

无法读取ssis中的对象变量

无法读取ssis中的对象变量,ssis,Ssis,需要一些帮助。我最近在为我的客户开发软件包时遇到了这个问题。 我将SQl任务的结果集保存在用户变量(对象)中,然后尝试在各种脚本任务中访问它。变量的范围设置为包级别。当我使用下面的代码时,我能够在S.Container的脚本任务中检索它的值,但是如果我在S.Container2的脚本任务中使用相同的代码,我就无法检索。在后面的示例中,“dt”只显示标题,而不是数据 这种特殊行为有什么原因吗。?我错过了什么 SQL任务代码----------- 脚本任务代码----------- 编辑::以下代

需要一些帮助。我最近在为我的客户开发软件包时遇到了这个问题。 我将SQl任务的结果集保存在用户变量(对象)中,然后尝试在各种脚本任务中访问它。变量的范围设置为包级别。当我使用下面的代码时,我能够在S.Container的脚本任务中检索它的值,但是如果我在S.Container2的脚本任务中使用相同的代码,我就无法检索。在后面的示例中,“dt”只显示标题,而不是数据

这种特殊行为有什么原因吗。?我错过了什么

SQL任务代码-----------

脚本任务代码-----------

编辑::以下代码也不起作用

Variables lockedVariables = null;
            Dts.VariableDispenser.LockForWrite("User::Variable");
            Dts.VariableDispenser.GetVariables( ref lockedVariables);
            object A;
             A= lockedVariables["User::Variable"].Value;
            lockedVariables.Unlock();
            DataTable dt = new DataTable();
            DataRow row = null;
            OleDbDataAdapter oleDA = new OleDbDataAdapter();
            oleDA.Fill(dt, A);
            foreach (DataRow row_ in dt.Rows)
            {
                row = row_;

            }

您确定没有意外地声明变量两次,一次声明包的作用域,一次声明第一个序列容器的作用域

编辑:调用Fill似乎可以清除源结果,如下所示:

    DataTable dt1 = new DataTable();
    OleDbDataAdapter oleDA = new OleDbDataAdapter();
    oleDA.Fill(dt1, Dts.Variables["Results"].Value);
    foreach (DataRow row_ in dt1.Rows)
    {
        MessageBox.Show(row_[0].ToString());
    }

    //Try and fill with the same data adapter
    DataTable dt2 = new DataTable();
    oleDA.Fill(dt2, Dts.Variables["Results"].Value); 
    foreach (DataRow row_ in dt2.Rows)
    {
        //This will never be hit
        MessageBox.Show(row_[0].ToString());
    }   

有一个错误报告给微软


虽然我仍然觉得记录集通常是一次性的集合。当您调用该Fill方法时,它将遍历记录集并将数据复制到DataTable中,直到记录集被使用为止

是的,我是。这只是一个变量。你能自己试试吗?@Akshay,好的,我试过了,结果和你一样。看起来调用Fill会清空源数据适配器。我会将您填写的数据表分配给一个新的对象变量?我不明白为什么只填充标题而不填充数据。1我又做了一件事,将执行SQL任务复制到S.Container2,然后一切都正常运行。这是该工具的开始行为。@Akshay,不,不是该工具,是调用fill清空行。元数据仍然存在,这就是为什么可以得到列名而没有行。试试我在上面编辑的例子,但它只是适配器。变量值应该仍然保存数据,不是吗?我也尝试过访问VariableDispenser,解锁它,但徒劳。我现在正为这个问题发疯。
Variables lockedVariables = null;
            Dts.VariableDispenser.LockForWrite("User::Variable");
            Dts.VariableDispenser.GetVariables( ref lockedVariables);
            object A;
             A= lockedVariables["User::Variable"].Value;
            lockedVariables.Unlock();
            DataTable dt = new DataTable();
            DataRow row = null;
            OleDbDataAdapter oleDA = new OleDbDataAdapter();
            oleDA.Fill(dt, A);
            foreach (DataRow row_ in dt.Rows)
            {
                row = row_;

            }
    DataTable dt1 = new DataTable();
    OleDbDataAdapter oleDA = new OleDbDataAdapter();
    oleDA.Fill(dt1, Dts.Variables["Results"].Value);
    foreach (DataRow row_ in dt1.Rows)
    {
        MessageBox.Show(row_[0].ToString());
    }

    //Try and fill with the same data adapter
    DataTable dt2 = new DataTable();
    oleDA.Fill(dt2, Dts.Variables["Results"].Value); 
    foreach (DataRow row_ in dt2.Rows)
    {
        //This will never be hit
        MessageBox.Show(row_[0].ToString());
    }