SQL Server Development Bookmark and Share   
 index > SQL Server Integration Services > Help with child package script component
 

Help with child package script component

I have this block of code that is in a child package (see below).

The idea is, I want to be able to run the child package by calling it from the parent packageAND sometimes I want to be able to run the child package on its own, in which case it will not have access to the variables in the parent package, i.e. "TEST". That is, the"TEST" variable will not be "seen" by the child package because the TEST variable lives at the parent level, not the child level.

In the case of running the child package on its own, it won't find the TEST variable, and it should fail.

However, I do not want the script task to fail as I have a try catch block but it fails anyway even with the exit try. What am I missing please?

Thank you.

Try
Dim vars As Variables
Dts.VariableDispenser.LockForWrite(“TEST� 'this is a variablein the parent package
Dts.VariableDispenser.GetVariables(vars)
Try
vars(“TEST�.Value = “I’m Done�br>
Catch ex As Exception
Throw ex
Finally
vars.Unlock()
End Try
Catch ex As Exception

�what can I put here so that the script task does not fail?

Exit try
‘Throw ex - do not want this
End Try

sadie2  Friday, January 11, 2008 11:22 PM

In my testing, it didn't seem to matter how the error was handled in the script- it still propagated the error to the package.

Another, even easier approach to resolving this - check for existence of the variable before trying to lock it. You can use the VariableDispenser.Contains method for this:

Code Block

If Dts.VariableDispenser.Contains("TEST") Then

Dts.VariableDispenser.LockForWrite("TEST")

jwelch  Saturday, January 12, 2008 7:16 PM
Why not go ahead and create the variable in the child package as well? You can set it to a default value in the package. Then use a parent package variable configuration to set it when it is called from a parent. That way the variable always exists, and if it has the default value, you know it wasn't set from the parent.

jwelch  Saturday, January 12, 2008 12:41 AM

Thanks that helps, do you have a link that explains how to set up a "parent package variable configuration" ?

p.s. Do you know why the Try-Catch returns an error in the above example?

sadie2  Saturday, January 12, 2008 12:56 AM
sadie519590 wrote:

Thanks that helps, do you have a link that explains how to set up a "parent package variable configuration" ?

Parent Package Variables: http://technet.microsoft.com/en-us/library/ms345179.aspx

sadie519590 wrote:

p.s. Do you know why the Try-Catch returns an error in the above example?

No, I'm not sure. I tried a quick test and got the same results as you - I'll play with it a bit more this weekend.

jwelch  Saturday, January 12, 2008 1:01 AM

From the CATCH block, try doing the following.

Code Block

Dts.TaskResult = Dts.Results.Success

Jacob Sebastian  Saturday, January 12, 2008 5:43 AM

In my testing, it didn't seem to matter how the error was handled in the script- it still propagated the error to the package.

Another, even easier approach to resolving this - check for existence of the variable before trying to lock it. You can use the VariableDispenser.Contains method for this:

Code Block

If Dts.VariableDispenser.Contains("TEST") Then

Dts.VariableDispenser.LockForWrite("TEST")

jwelch  Saturday, January 12, 2008 7:16 PM
Thanks!

sadie2  Monday, January 14, 2008 8:51 PM

You can use google to search for other answers

Custom Search

More Threads

• Calling all ssis problem solvers!
• SSIS Importing XML and using a TAG from higher hierarchy
• Safety of using .NET static members as configuration transport.
• populate variable values
• Aha! Multiple Header Records
• SSIS Error 12291
• Problem: SSIS Package failure using 32-bit DTExec and 64-bit DTExec
• My own Dataflow Component. How make a property with list of predefined values?
• ADO.NET vs OLE DB: which one is faster?
• wizard for creating interface to ssis package?