微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

sql-server-2005 – SSIS脚本组件写入变量

这是sql 2005.

我在数据流任务中有一个脚本组件.我想从输入列中读取并将数据写入全局用户变量.

我已经设置了输入列,并将我的全局用户变量作为ReadWriteVariable添加到脚本组件属性中.

这是我的代码,我只是想在这里改变全局用户变量的值,但它不起作用.当我在另一个任务中写出变量的值时,它仍然具有认值:

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.sqlServer.Dts.Runtime
Imports Microsoft.sqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.sqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain
    Inherits UserComponent
    Dim updatesql As String

    Public Sub Main()
        Dim vars As IDTSVariables90

        Variabledispenser.LockOneForWrite("sql_ATTR_Update",vars)
        vars("sql_ATTR_Update").Value = "Test"
        vars.Unlock()
    End Sub


    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
        'updatesql = Row.ITMID + Row.PRCCAT
    End Sub

End Class

我也试过没有运气:

Me.ReadWriteVariables("sql_ATTR_Update").Value = "Test"

解决方法

我想到了.

来自MS:

In Script component code,you use
typed accessor properties to access
certain package features such as
variables and connection managers.

The PreExecute method can access only
read-only variables. The PostExecute
method can access both read-only and
read/write variables.

For more information about these
methods,see Coding and Debugging the
Script Component.

http://msdn.microsoft.com/en-us/library/ms136031.aspx

看起来Dts仅在Script Task中可用.

这是代码的样子:

Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.sqlServer.Dts.Runtime
Imports Microsoft.sqlServer.Dts.Pipeline.Wrapper
Imports Microsoft.sqlServer.Dts.Runtime.Wrapper

Public Class ScriptMain
    Inherits UserComponent
    Dim updatesql As String


    Public Overrides Sub PostExecute()
        Me.ReadWriteVariables("sql_ATTR_Update").Value = "Test"
    End Sub

    Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
        'updatesql = Row.ITMID + Row.PRCCAT
    End Sub

End Class

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐