Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

for loop container, script task and an error message

Status
Not open for further replies.

lupidol

Programmer
Apr 23, 2008
125
IL
I everyone,
I'm learning SSIS from a book but the most simple example is not working.
The "For loop container" I assigned "xyz" as name.
I added a variable onto the "variables" window and called it "counter" Its scope was set to "xyz" which is the whole container.
Inside the "for loop" ("xyz") editor i assigned values as follows:
"initexpression"-"@counter=0"
"eval expression"-"@counter<5"
"assign expression"-"@counter=@counter+1"

I added "Script task" onto the "For loop" (xyz) container and into the "Script task editor" I assigned
the following values:
"ReadOnlyVariables"-"counter"
Its design script is set to:

Code:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime

Public Class ScriptMain
    Public Sub Main()
        Dim variables As Variables
        If Dts.Variables.Contains("Counter") = True Then
            Dts.VariableDispenser.LockOneForRead("Counter", variables)
        End If

        MsgBox("You are in iteration: " & CStr(variables("Counter").Value))
        Dts.TaskResult = Dts.Results.Success

    End Sub
End Class
Runnig it i get the following error message:

"DTS Script task has encountered an exeption in user code:
Project name:ScriptTask_e7d98dbad0de4041bcdc9079a5c2fa65
Object reference not set to an instance of an object.."
The line where the error occurs is from within the above script:

Code:
"MsgBox("You are in iteration:" " & CStr(variables("Counter").value))
Anyone understands what that means? What is "object reference" and how do i set it to an instance of an object?
Thanks
 
Try changing the "variables("Counter").Value" to "DTS.variables.item("Counter").Value". Also, don't forget the variable names are case sensitive.

Denny
MCSA (2003) / MCDBA (SQL 2000)
MCTS (SQL 2005 / Microsoft Windows SharePoint Services 3.0: Configuration / Microsoft Office SharePoint Server 2007: Configuration)
MCITP Database Administrator (SQL 2005) / Database Developer (SQL 2005)

My Blog
 
Hi mrdenny !
Sorry for the late response.
I finally found the reason to the error.
It didnt comply with case sensitive low that is in SSIS.
I defined "counter" in "variables" and the book's example referred to "Counter".
I didnt present that information in my notification because i was not aware of it.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top