Enable/Disable tasks in Script task
I have three task in my SSIS package,1. Script Task2. Execute Process Task3. FTP TaskI want to enable disable Execute Process Task and FTP Task on runtime using script task, How to do that?Do we have any property of dts using which we can access property of other task iin script task like Dts.Connection("Connectionname") for Connection Controls?
June 17th, 2008 5:56pm

There is no way to modify the properties of tasks in a running package through code in SSIS. This ability in DTS made packages incredibly difficult to maintain, and it has been removed. The only way to share information between tasks in SSIS is via package variables. And with the use of variables and expressions, the problem you need to solve can be easily solved, even if the approach is different than it was in DTS. Here's what to do: Create two Boolean variables: RunProcessTask and RunFtpTask In the Script task, set these variables with the appropriate values based on yourbusiness logic After the Script task, have two precedence constraints that connectit to the two other tasks Edit the properties of each precedence constraint so that that task only runs when the appropriate variable is set to true, such as @RunProcessTask or @RunFtpTask I have a blog post here http://bi-polar23.blogspot.com/2008/02/expressions-and-precedence-constraints.htmlthat should help you get started with expressions and precedence constraints. Good luck!
Free Windows Admin Tool Kit Click here and download it now
June 17th, 2008 6:10pm

Task has a property named "Disabled". Here is a simple way to enable/disable task. 1. Add a variable with DataType of Boolean. For example, named @DisableTask 2. In task's expression, set "Disabled" expression as variable @DisableTask 3. Use Script Task to Lock/Change/Unlock the variable's value. For your last question, I have a code sample. I didn't try in Script Task. It mayuseful for you. Executable exe = package.ExecutablesTaskHost taskhost = exe as TaskHost;taskhost.Disable=true;
June 17th, 2008 6:25pm

Hong Chang - MSFT wrote: Task has a property named "Disabled". Here is a simple way to enable/disable task. 1. Add a variable with DataType of Boolean. For example, named @DisableTask 2. In task's expression, set "Disabled" expression as variable @DisableTask 3. Use Script Task to Lock/Change/Unlock the variable's value. Just be aware that once a task's Disabled property is set to True, it can never be re-enabled during the package execution. It's as if the task no longer exists for the current run of the package. This is why using precedence constraints and expressions is a safer and (in my opinion anyway) preferred approach.
Free Windows Admin Tool Kit Click here and download it now
June 17th, 2008 6:34pm

Another way, the way I used to do it in DTS is (not the best for SSIS) 1) to create a execute sql task. 2) In properties of this task write a statemenet that always executes, such as Select 1 3) Use failed precedence constraint (the red one), and connect from the always executes task to the task you want to disable and the pipeline will run up to that point and stop John KKnowledgy Consultinghttp://knowledgy.org/
June 17th, 2008 11:19pm

HiI do something like that, but in my case the task to execute (or not) is one step in the chain.If I use the precedence constraints, execution just stops there. How can I make the packagejust "skip" a task (not using the disabled property, because I really need to enable/disableat runtime.)Thanks,J.
Free Windows Admin Tool Kit Click here and download it now
June 23rd, 2008 1:54pm

Mouse click on the constraint, you can set some properties of the constraint. For example, you can set "Value"="Completion" that mean the process will continue after the task completedno matter whether success or fail. And you can also set "EvalOp" to other values to implement your logic.
June 23rd, 2008 3:13pm

Hong Chang: that's the point: because the constrained task is not executed, is it also never "completed", thus the execution stops right there.Anyway, I build a way-around: imagine the task flow is A --> B --> C , where "B" should be executed based on a runtime condition. If I constraint "B" with a precedence constraint, execution will stop before B if the constraint is not met. So, that's not working.So I made it like this : A --> B with precedence constraintA --> D with inverse precedence constraintand thenB, D --> C with "or" constraintwhere D is a dummy task (which I even set disabled). In any case, B or D (exclusive or) will be executed (and completed), so execution can continue after that.That's a little complex, but I haven't found a shorter/smarter way CheersJ.
Free Windows Admin Tool Kit Click here and download it now
June 25th, 2008 3:40pm

Hi, We can't D/E tasks in SSIS but we can do execute tasks based on prev task result using PC expression and variables. Thanks SSSSSSIIIIIIIIIIISSSSSSSS
June 25th, 2008 4:14pm

You could also get away with not using a dummy task at all (although you will have to usea Sequence Container).Put A and B in a sequence container, using the conditional constraint. Attach C to the sequence container with a regular constraint. Based on what A does, B may or may not get executed - but the sequence will be "complete", and therefore will then execute C.
Free Windows Admin Tool Kit Click here and download it now
November 12th, 2009 9:09pm

Todd, indeed, it requires an extra task but the sequence task is a "nicer" solution than the dummy task. Good idea! Thanks Joachim.
February 7th, 2011 3:25am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics