November 12, 2007 at 4:01 am
Is it possible to disable a task dynamically? For example, if I had a boolean variable could I set a task to run if the variable is set to True and ignore the task if the variable were set to False? The constraint on the task would still have to be adhered to i.e. the task following the dynamically set task would still need to be executed.
November 12, 2007 at 6:44 am
You could put a T-SQL task before it that has a SQL statement something like:
IF EXISTS(SELECT MyValue FROM MyVariables WHERE MyVarName='NORUNTASK1' AND MyValue = 0)
RAISERROR('Do Not Run',16,9)
Then, configure the on success of the task to go to the next step and the on error of the task to go to the step after the next one.
Of course, if your task is a T-SQL step, you could just put the conditional logic right in your task.
November 12, 2007 at 6:50 am
That sounds like the way forward! I'll give this a go and let you know if there are any problems.
Thanks
November 12, 2007 at 1:35 pm
I have tried changing the value of the Disable property on the task dynamically, but that didn't work.
I did place the task to be skipped in a For Loop Container and fed the EvalExpression a variable set by a preceeding task to 0 or 1. 0 and nothing in the For Loop Container will run, 1 and the Task(s) in the For Loop Container run once. The advantage to this method is that you can have several Tasks skipped.
I wonder if the Sequence Container can be configured to skip?
I did all this before I figured out how to enable precedence contraints with variables, DUH! In my case the Task to skip was the last one.
November 13, 2007 at 4:31 am
Hi,
Did you control the constraints using a similar method to the one suggested by Michael in the earlier post?
November 13, 2007 at 5:27 am
You could not set the task as disabled in the expressions for the task because the task would already have the control when the expression is evaluated. You may be able to do this with expressions if you put the task you wanted to disable into another container and used the expression evaluation for the container to disable the task.
You always have to be careful about the order in which variables are scoped and expressions will be evaluated. This is one reason I try to avoid them. Another reason is that the VS user interface hides the fact that you have used expressions a little too well and I find myself having to include a lot of annotations so I remember them the next time I have to open a package.
You could also handle this type of logic with an event handler. Make a task that errors if your flag is set and put your net set of tasks in the error handler for the task. I don't think it is a good idea, but it would work.
So, you may be able to do this in another way, but using precedence constraints is what you are supposed to do.
November 13, 2007 at 7:05 am
Hi,
I've tried a variation on Michael's suggestion by using a Script Task and a variable. The code for the script task is:
Dim blnResetData As Boolean = System.Convert.ToBoolean(Dts.Variables("blnReset").Value)
If blnResetData = False Then
Dts.TaskResult = Dts.Results.Failure
Else
Dts.TaskResult = Dts.Results.Success
End If
The task has two precedence constraints, Success leads to one task and Failure leads to another. However, if I set blnResetData to False the package fails even though the Script Task has FailPackageOnFailure set to False.
Any ideas?
November 13, 2007 at 8:19 am
Again, I would not recommend doing it this way, using error handlers to drive control flow is going to lead you to a list of other issues.
Your problem is probably that you need to set the MAX Error Count properties.
To have an error essentially allow your package to resume, you need to set the MAX Error Count for your task and ever container that the task is in - including the package itself.
November 13, 2007 at 8:26 am
Hi Michael,
I thought I was roughly doing what you suggested in your earlier post. If my task fails the Failure precedence constraint skips the next task and is attached to the final task in the package. If the task succeeds the Success precedence constraint leads to the next task in the package etc.
Please let me know if this is not what you meant.
Thanks
David
November 14, 2007 at 7:20 am
Steve was nice enough to tell me how to post an attachment.
I have attached a zip file with a word document containing some basic instructions and some pictures.
November 14, 2007 at 8:26 am
Hi Michael,
That's great, I am now able to skip the task!
Thanks
David
November 14, 2007 at 8:47 am
No problem.
That was far easier to describe with pictures. I should have done that in the first place.
Viewing 12 posts - 1 through 11 (of 11 total)
You must be logged in to reply to this topic. Login to reply