SSIS 读/写脚本任务中的变量

发布于 2024-12-09 10:01:19 字数 662 浏览 0 评论 0原文

我有一个名为 Valint 的变量,我需要在脚本任务中读取/写入该变量,但它似乎不起作用:

public class scriptmain
inherits usercomponent

dim counter as integer
dim Valint as integer
.....


Public sub new()
counter = 0
end sub

public overrides sub input0_processintputrow(byval row as input0buffer)
Dim vars as IDTSvariables100 = nothing

Me.variableDispenser.lockforread("User::Valint")
Me.variableDispenser.GetVariables(vars)

counter = CType (vars("User:: Valint").Value, integer)
vars.Unlock()

counter +=1

Me.VariableDispenser.LockoneForWrite("User::Valint", vars)
vars("User::Valint").Value = counter
vars.Unlock()
End Sub

出于某种原因,我的输出始终为 0

I have a variable called Valint that i need to read/write to in a script task, but it doesn't seem to work:

public class scriptmain
inherits usercomponent

dim counter as integer
dim Valint as integer
.....


Public sub new()
counter = 0
end sub

public overrides sub input0_processintputrow(byval row as input0buffer)
Dim vars as IDTSvariables100 = nothing

Me.variableDispenser.lockforread("User::Valint")
Me.variableDispenser.GetVariables(vars)

counter = CType (vars("User:: Valint").Value, integer)
vars.Unlock()

counter +=1

Me.VariableDispenser.LockoneForWrite("User::Valint", vars)
vars("User::Valint").Value = counter
vars.Unlock()
End Sub

For some reason my output is always 0

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

柠北森屋 2024-12-16 10:01:19

这是在数据流任务中,是吗?您不能在脚本转换中修改变量,至少在 processinputrow 子例程期间是这样。

幸运的是,似乎您正在做的修改类型可以完成 - 只是在不同的子例程中。

Donald Farmer 所著的《SSIS Scripting Beta》书距离我有一千英里,所以请原谅这段代码的不精确性。重要的是您只能从 PostExecute 事件写入用户变量。

public class scriptmain
inherits usercomponent

dim counter as integer
dim Valint as integer
.....


Public sub new()
counter = 0
end sub

public overrides sub input0_processintputrow(byval row as input0buffer)
    counter +=1
End Sub

Public overrides sub PostExecute()
    Dim vars as IDTSvariables100 = nothing

    Me.variableDispenser.lockforread("User::Valint")
    Me.variableDispenser.GetVariables(vars)

    counter = CType (vars("User:: Valint").Value, integer)
    vars.Unlock()
    Me.VariableDispenser.LockoneForWrite("User::Valint", vars)
    vars("User::Valint").Value = counter
    vars.Unlock()
End Sub

This is in a data flow task, yes? You can't modify a variable in the script transformation, at least during the processinputrow subroutine.

Fortunately, it seems like the type of modification you are doing can be done-just in different subroutines.

My SSIS Scripting Beta book by Donald Farmer is a thousand miles from me so please forgive the imprecision of this code. The important thing is that you can only write to the user variable from the PostExecute event.

public class scriptmain
inherits usercomponent

dim counter as integer
dim Valint as integer
.....


Public sub new()
counter = 0
end sub

public overrides sub input0_processintputrow(byval row as input0buffer)
    counter +=1
End Sub

Public overrides sub PostExecute()
    Dim vars as IDTSvariables100 = nothing

    Me.variableDispenser.lockforread("User::Valint")
    Me.variableDispenser.GetVariables(vars)

    counter = CType (vars("User:: Valint").Value, integer)
    vars.Unlock()
    Me.VariableDispenser.LockoneForWrite("User::Valint", vars)
    vars("User::Valint").Value = counter
    vars.Unlock()
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文