2

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

这种特殊行为的任何原因。?我错过了什么?

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

select * from dimproduct

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

 DataTable dt = new DataTable();
 DataRow row = null;
 OleDbDataAdapter oleDA = new OleDbDataAdapter();
 oleDA.Fill(dt, Dts.Variables["Variable"].Value);
    foreach (DataRow row_ in dt.Rows)
     {
       row = row_;
     }

在此处输入图像描述

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

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_;

            }
4

2 回答 2

0

你确定你没有不小心声明了两次变量,一次是在包的范围内,一次是在第一个序列容器的范围内?

编辑:调用 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());
    }   
于 2013-08-12T16:43:28.397 回答
0

有一个关于它的错误报告给微软..

https://connect.microsoft.com/SQLServer/feedback/details/265841/ssis-cannot-clone-a-recordset-built-using-the-recordset-destination

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

于 2013-08-16T12:30:41.247 回答