SSIS 2008 使用相同的变量进行行计数和脚本组件
我有一个行计数组件,它使用全局变量 X 来存储数字;到目前为止,它是规则的,但是如果我添加一个在只读变量中包含 X 的脚本组件,然后在其中出于某种目的使用它,流程会挂起一会儿,然后崩溃,说行计数需要一个有效的变量。
是否可以将行计数存储在变量中,然后从脚本 comp 中读取该变量。 ?
I have a row count component that uses a global variable X to store the number; up to this point it rules but then if I add a script component that has X among its ReadOnly variables and then use it inside it for some purpose, the flow hangs on for a moment then it crashes saying row count needs a valid variable.
Isn't it possible to store the row count in a variable and then read this variable from a script comp. ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您不能在同一数据流中的任何其他地方使用在行计数转换中填充的变量。在数据流的预执行阶段,行计数锁定变量。尝试在脚本组件中使用该变量将使脚本(同时)尝试相同的操作,因此 SSIS 会引发错误。
但即使这没有发生,也会发生其他事情。当您的数据流工作并且行传递到行计数时,它实际上并没有用行计数填充 SSIS 变量。这将是非常低效的,因为行计数实际上是一个 COM 组件,而 SSIS 变量是 .Net。从 COM 使用 .Net 资源是“昂贵的”,反之亦然。因此,行计数将值累加到本地代码变量中。在执行后阶段,行计数将其收集的值推送到 SSIS 变量中。关键点是 PostExecute 阶段发生在数据流完成之后。如果您能够在数据流中间的任何时间查看该变量(有多种方法),您将看到它的值为零(或在数据流开始之前设置的任何值)。
如果您想使用行计数来执行条件操作,或更新流中的行,您有多种选择:
You can not use a variable you populate in a Row Count transformation anywhere else in that same data flow. In the PreExecute phase of the data flow, the Row Count locks the variable. Attempting to use the variable in a Script component would have the Script try the same thing (at the same time) and SSIS therefore throws an error.
But even if that didn't happen, here's what else is going on. As your data flow works, and rows pass into the Row Count, it isn't actually filling the SSIS variable with the row count. That would be very inefficient, since the Row Count is actually a COM component and the SSIS variables are .Net. It's "expensive" to use .Net resources from COM and vice-versa. So the Row Count accumulates the value in a local code variable. In the PostExecute phase, the Row Count then pushes the value it collected into the SSIS variable. The key point is that the PostExecute phase happens after the data flow is complete. If you were able to view the variable at any time during the middle of the data flow (there are ways) you would see it valued at zero (or whatever value it was set to before the data flow started).
If you want to use a count of rows to perform a conditional action, or update rows within the flow, you have a couple choices:
不,我认为不可能将
Row Count
中使用的变量也用于Script Component
中。据我了解,该变量在行计数转换中被锁定以进行写入,并且在脚本组件转换中不可用。
那么,您想对脚本组件内的变量做什么?如果您可以指定您的要求,也许有人可以建议替代方案。
此链接中的文章建议了一种方法:http://consultingblogs.emc.com/jamiethomson/archive/2007/02/28/SSIS-Nugget_3A00_-Output-the-rowcount.aspx
No, I don't think it is possible to use the variable used in
Row Count
to be used inScript Component
as well.My understanding that the variable is locked for write in the Row Count transformation and isn't available in Script Component transformation.
So, what are you trying to do with the variable inside Script Component? If you can specify your requirement, may be someone can suggest an alternative.
The article in this link suggests an approach: http://consultingblogs.emc.com/jamiethomson/archive/2007/02/28/SSIS-Nugget_3A00_-Output-the-rowcount.aspx
我们也可以在脚本任务中使用相同的变量“Rowcount”...仅当该变量的范围位于包级别时。[全局变量]。
We can use the same variable 'Rowcount' to use in the script task as well ... only when the scope of that variable is at package level.[Global variable].
大多数时候我在控制流中使用脚本,在数据流中使用行计数。
1)如果您希望首先在控制流中进行数据流任务(将执行行计数活动)。
2)然后将脚本拖到其下方并使用行计数。
这是相同的例子。
http://www.c- Sharpcorner.com/uploadfile/muralidharan.d/how-to-use-rowcount-in-ssis/
Most of the time I have used Script in the control flow and row count in the data flow.
1) If you want the count first make the data flow task(which will do the row count activity) in the control flow.
2) then drag the script beneath it and use the rowcount.
here is the example of the same.
http://www.c-sharpcorner.com/uploadfile/muralidharan.d/how-to-use-rowcount-in-ssis/