编程语言
首页 > 编程语言> > c# – SSIS只读变量被更改

c# – SSIS只读变量被更改

作者:互联网

我有一个包,其中我有两个组件:第一个是执行和获取ADO结果集的SQL任务,第二个是脚本任务,我将结果集转换为System.Data.DataTable两次,类似于:

 System.Data.DataTable t1= new System.Data.DataTable();
 OleDbDataAdapter adp = new OleDbDataAdapter();
 adp.Fill(t1, Dts.Variables["ResultSet"].Value);

 System.Data.DataTable t2= new System.Data.DataTable();
 OleDbDataAdapter adp2 = new OleDbDataAdapter();
 adp2.Fill(t2, Dts.Variables["ResultSet"].Value);

结果是t1正确填充,但t2保持为空;更重要的是,我已经将[User :: ResultSet]显式设置为只读变量,似乎变量刚刚被清空,即使我稍后再添加一个脚本任务并再次执行相同的操作,填充的DataTable仍然是空的.

有很多方法可以规避我的情况,所以我不希望在这里找到解决方案.但我想弄清楚那些事情:OleDbDataAdapter.Fill对原始数据集有副作用,我的只读变量如何改变它的值?

解决方法:

我不认为这会改变Read-Only Recordset变量值,问题是当使用Adapter.Fill方法用记录集填充数据表时,Record集仍然打开你必须明确地关闭它才能够与其他适配器一起使用它. (当你再次尝试从中读取时,它已完成提供行,所以你试图从最后读取)

从以下Microsoft文章:

> Filling a DataSet with an ADO Recordset or Record
> OleDbDataAdapter.Fill Method (DataTable, Object)

CAUTION When using ADO Recordset or Record objects in conjunction with .NET Framework applications, always call Close when you are finished. This ensures that the underlying connection to a data source is released in a timely manner, and also prevents possible access violations due to unmanaged ADO objects being reclaimed by garbage collection when existing references still exist.

Note that the OleDbDataAdapter.Fill overload that takes a DataSet and an ADO object implicitly calls Close on the ADO object when the Fill operation is complete. You need to explicitly close the ADO Recordset or Record object after calling the OleDbDataAdapter.Fill overload that takes a DataTable.

我没有真正找到如何在使用Fill方法后关闭SSIS记录集,但是我找到了类似问题的链接以及变通方法:

> Reading a Recordset multiple times gives 0 rows

标签:c,sql-server,ssis,etl,script-task
来源: https://codeday.me/bug/20190622/1263172.html