![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
-----Original Message----- Hello, I modified this script to run creat four tasks using customTasks. When I executed this script, task, I was expecting four "Hello World" messages to appear, why it did not? Ahmed. '************************************************* ******** * ************ ' Visual Basic ActiveX Script '************************************************* ******** * ************** Option Explicit Function Main() Dim objPackage Dim objStep Dim objTask Dim objScripTask Dim Index Dim taskname Set objPackage = DTSGlobalVariables.Parent For Each objTask in objPackage.Tasks For Index = 1 to 4 taskname = "AXScr_Task" & Index IF objTask.Name = taskname Then objPackage.Tasks.Remove(taskname) End If Next Next For Each objStep in objPackage.Steps IF objStep.Name = "AXScr_Step" Then objPackage.Steps.Remove("AXScr_Step") End If Next 'create step and task, specify script, func name and language ' Set objStep = objPackage.Steps.New DTSGlobalVariables("GlobalOne").Value = 3 For Index = 1 to 4 Set objTask = objPackage.Tasks.New ("DTSActiveScriptTask") Set objScripTask = objTask.CustomTask objScripTask.Name = "AXScr_Task" & Index MsgBox objScripTask.Name objScripTask.ActiveXScript = _ "Function Main()" & vbCrLf & _ "MsgBox ""Hello World "" " & vbCrLf & _ "If DTSGlobalVariables( ""GlobalOne"" ) 0 Then" & vbCrLf & _ vbTab & "Main = DTSTaskExecResult_Success" & vbCrLf & _ "Else" & vbCrLf & _ vbTab & "Main = DTSTaskExecResult_Failure" & vbCrLf & _ "End If" & vbCrLf & _ "End Function" objScripTask.FunctionName = "Main" objScripTask.ScriptLanguage = "VBScript" 'link step to task to package 'objStep.TaskName = objScripTask.Name 'objStep.Name = "AXScr_Step" 'objPackage.Steps.Add objStep objPackage.Tasks.Add objTask Next objPackage.FailOnError = False Set objPackage = Nothing Set objStep = Nothing Set objTask = Nothing Set objScripTask = Nothing Main = DTSTaskExecResult_Success End Function . |
#3
| |||
| |||
|
|
-----Original Message----- Did you setup a workflow so that the new tasks would execute after this initial task was finished? Not sure you had to remove tasks and steps first. Just set up your shell tasks with proper workflow and populate them with requirted data. Ken '************************************************* ********* |
#4
| |||
| |||
|
|
-----Original Message----- Hi Ken, I added the steps and it works now, i also opened the workflow of this Task and checked "Execute on Main Package thread". My question is those tasks should be executed on their own thread, concurrent operation. I will be loading lots of data within those new created dynamic tasks? Ahmed. -----Original Message----- Did you setup a workflow so that the new tasks would execute after this initial task was finished? Not sure you had to remove tasks and steps first. Just set up your shell tasks with proper workflow and populate them with requirted data. Ken '************************************************* ******** * ************ ' Visual Basic ActiveX Script '************************************************* ******** * ************** Function Main() Dim objPackage Dim objStep Dim objTask Dim objScripTask Dim Index Dim taskname Dim stepname Set objPackage = DTSGlobalVariables.Parent For Each objTask in objPackage.Tasks For Index = 1 to 4 taskname = "AXScr_Task" & Index IF objTask.Name = taskname Then objPackage.Tasks.Remove(taskname) End If Next Next For Each objStep in objPackage.Steps For Index = 1 to 4 stepname = "AXScr_Step" & Index IF objStep.Name = stepname Then objPackage.Steps.Remove(stepname) End If Next Next 'create step and task, specify script, func name and language DTSGlobalVariables("GlobalOne").Value = 3 For Index = 1 to 4 Set objStep = objPackage.Steps.New Set objTask = objPackage.Tasks.New("DTSActiveScriptTask") Set objScripTask = objTask.CustomTask objScripTask.Name = "AXScr_Task" & Index objScripTask.ActiveXScript = _ "Function Main()" & vbCrLf & _ "MsgBox ""Hello World "" " & vbCrLf & _ "If DTSGlobalVariables( ""GlobalOne"" ) > 0 Then" & vbCrLf & _ vbTab & "Main = DTSTaskExecResult_Success" & vbCrLf & _ "Else" & vbCrLf & _ vbTab & "Main = DTSTaskExecResult_Failure" & vbCrLf & _ "End If" & vbCrLf & _ "End Function" objScripTask.FunctionName = "Main" objScripTask.ScriptLanguage = "VBScript" 'link step to task to package objStep.TaskName = objScripTask.Name objStep.Name = "AXScr_Step" & index objPackage.Steps.Add objStep objPackage.Tasks.Add objTask Next objPackage.FailOnError = False Set taskname = Nothing Set stepname = Nothing Set objPackage = Nothing Set objStep = Nothing Set objTask = Nothing Set objScripTask = Nothing Main = DTSTaskExecResult_Success End Function . |
#5
| |||
| |||
|
|
Hi Ken, I added the steps and it works now, i also opened the workflow of this Task and checked "Execute on Main Package thread". My question is those tasks should be executed on their own thread, concurrent operation. I will be loading lots of data within those new created dynamic tasks? |
#6
| |||
| |||
|
|
-----Original Message----- In article <009801c377e6$e01c7290$a101280a (AT) phx (DOT) gbl>, Ahmed Zayan ahmed.zayan (AT) boeing (DOT) com> writes Hi Ken, I added the steps and it works now, i also opened the workflow of this Task and checked "Execute on Main Package thread". My question is those tasks should be executed on their own thread, concurrent operation. I will be loading lots of data within those new created dynamic tasks? Adding and removing tasks dynamically at run-time is not a good idea, and neither is it supported I believe. Can you not create a package and change the tasks content or workflow as Ken suggests. -- Darren Green (SQL Server MVP) DTS - http://www.sqldts.com PASS - the definitive, global community for SQL Server professionals http://www.sqlpass.org . |
#7
| |||
| |||
|
|
The example I sent works fine. This is the second time I hear the same advice against creating dynamic tasks. Can you explain why, and how I implement the same example I posted? Each task supposes to be doing a different function, loading different table. I though the example you sent had a problem which is why you posted it, |
#8
| |||
| |||
|
|
-----Original Message----- In article <032d01c3781a$ef10e310$a101280a (AT) phx (DOT) gbl>, I though the example you sent had a problem which is why you posted it, or have a missed the point? Sorry Dareen, I later sent script that worked. |
|
I was advised by a member of the SQL product team, and I'm sure they have posted similar warnings on the newsgroup, but I couldn't find it just now. I trust their advice and pass it on when I can, even if I can not fully explain it. You have several units of work, so why not use either workflow to turn on or off pre-existing tasks, coupled with changing those existing tasks at run-time if required. For a more modular approach you could break the units of work down into multiple packages and call a package from another package. Maybe I could not explain what I am trying to do clearly. |
|
-- Darren Green (SQL Server MVP) DTS - http://www.sqldts.com PASS - the definitive, global community for SQL Server professionals http://www.sqlpass.org . |
#9
| |||
| |||
|
|
snip Maybe I could not explain what I am trying to do clearly. The idea is the task, the one I sent as an example will acts like controller by monitoring a job queue and assigned each task, max of four, from this queue to each task to execute. Ahmed. |
![]() |
| Thread Tools | |
| Display Modes | |
| |