Wednesday, March 7, 2012

Custom error msg breaks my error handler

Hi,

I added this line of code to my error handler script, in red.

User:Tongue TiedcriptError is a package-level string variable

User:Tongue TiedcriptError has a value assigned to it when another script encounters an error condition (which I define)

I added "User:Tongue TiedcriptError" as a read-only variable to the error handler script task.

Public Sub Main()

Dim messages As Collections.ArrayList

Try

messages = CType(Dts.Variables("errorMessages").Value, Collections.ArrayList)

Catch ex As Exception

messages = New Collections.ArrayList()

End Try

messages.Add(Dts.Variables("SourceName").Value.ToString)

messages.Add(Dts.Variables("ErrorDescription").Value.ToString())

messages.Add(Dts.Variables("scriptError").Value.ToString)

Dts.Variables("errorMessages").Value = messages

Dts.TaskResult = Dts.Results.Success

End Sub

Now, when I run the package, and an it encounters an error, it task just hangs, that is, it stays yellow instead of turning red... if I remove the line in red above, it works ok again.

Why would this line cause a problem?

Thanks

Make sure you are unlocking the scriptError variable in the first task. It might help if you post the script from that task.|||

Hi,

What do you mean by "unlocking the scriptError variable"?

Thanks

|||Dts.Variables.Unlock()|||

I will try that. Why is unlocking necessary? I've never run into this before.

Thanks

|||If the first task is raising an error, the error handling task can be fired before the variable is unlocked in the first task. Make sure that you unlock it in the error handler in the first script.|||

This is the part of my code that seems to be causing the problem. I am trying to set the "scriptError" variable to the error message below. As you can see, I am setting the Dts.TaskResult to "failure" BEFORE assigning the value to my variable. The "failure" causes execution to go to my Error Handler script task. That's where it hangs.

Perhaps I should put the the "failure" AFTER the variable assignment.

I don't understand all this "unlocking" stuff quite yet. What do you mean by "unlock it in the error handler"? Perhaps that doesn't apply here, I don't know.

Thanks

Else

Dts.TaskResult = Dts.Results.Failure

Dts.Variables("scriptError").Value = "The extracts in " & CStr(Dts.Variables("Folder").Value) & " are not current! Data NOT loaded."

End If

|||Adding

Dts.Variables.Unlock()

right after the variable is written to (but not before) works!

No comments:

Post a Comment