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

前端之家收集整理的这篇文章主要介绍了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

猜你在找的MsSQL相关文章