Increment Value in script component

  • Hello all,

    Seems like this should be simple but I can seem to figure ou how to solve the error I'm getting. I have a package with an integer variable (Let's call it ID). ID is set in to a value it gets from a SQL table in a execute SQL task.

    I then have a data flow task which contains an OLEDB source, a script component and a oledb destination. In the script component I simply want to increment all the rows using ID as the starting value. So for example if ID = 10 then the first row in the script component output column name VisitID will be 11 then 12 and so on.

    Problem i'm having is that I'm getting the error: the collection of variables locked for read and write access is not available outside of postexecute

    What I don't understand is that I'm not even trying to write to the variable ID yet i'm getting this error. I'm only writing to a variable created inside the script component. Here is my code below:

    Public Class ScriptMain

    Inherits UserComponent

    Dim VisitID As Integer

    Public Overrides Sub InputData_ProcessInputRow(ByVal Row As InputDataBuffer)

    If VisitID = 0 Then

    VisitID = Me.Variables.ID

    VisitID += 1

    Else

    VisitID += 1

    End If

    Row.VisitID = VisitID

    End Sub

    End Class

    I've also tried putting it in a postexecute and I still get the same error. Can anyone see what i'm doing wrong?

    Thanks,

    Strick

  • This is a problem I have dealt with as well. Since you are not writing to the ID variable you should not include it in the ReadWrite Variables property of the script component, but just in the ReadOnly Variables property of the Script Component.

  • Under Custom Properties on the Script panel of the Script Transformation Editor, did you enter your variable name in the "ReadOnlyVariables" property? You must do this for your variable to be available to your script.

    You would specify it as "User::ID".

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply