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

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...