You can use Microsoft® ActiveX® scripts to customize the execution of steps in a Data Transformation Services (DTS) package. Because the code is run before the steps executes, you can use an ActiveX script in a workflow to:
You can also use a step ActiveX script to initialize or reference global variables. For more information, see Using Global Variables with DTS Packages.
To add ActiveX workflow scripts in DTS Designer
The following examples show how to implement ActiveX workflow scripts in DTS Designer. You can also add workflow ActiveX scripts programmatically. For more information, see Adding DTS ActiveX Scripts.
The following example, written in Microsoft Visual Basic® Scripting Edition (VBScript), uses an ActiveX script to turn a step on or off based on the existence of a file:
Function Main()
Dim fso 'File system object
Set fso = CreateObject("Scripting.FileSystemObject")
IF (fso.FileExists("C:\temp\download.tmp")) THEN
Main = DTSStepScriptResult_ExecuteTask
ELSE
Main = DTSStepScriptResult_DontExecuteTask
END IF
End Function
The following example, written in VBScript, checks for the presence of a file five times before terminating the step. The global variable retries stores the number of attempted file checks:
Function Main()
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
IF NOT(fso.FileExists("C:\MyFile.txt")) THEN
DTSGlobalVariables("retries").Value =
DTSGlobalVariables("retries").Value + 1
IF DTSGlobalVariables("retries").Value > 5 THEN
Main = DTSStepScriptResult_DontExecuteTask
ELSE
MsgBox "Retry #" & DTSGlobalVariables("retries").Value
Main = DTSStepScriptResult_RetryLater
END IF
ELSE
Main = DTSStepScriptResult_ExecuteTask
END IF
End Function
The following example of ActiveX script step code, written in VBScript, is assigned to the second step in a two-step workflow connected with a precedence constraint (Step 1 -> On Completion precedence constraint -> Step 2).
The ActiveX script associated with Step 2 serves as a loop. The script operates as follows:
Function Main()
Dim oPkg
DTSGlobalVariables("counter").Value = _
DTSGlobalVariables("counter").Value + 1
If DTSGlobalVariables("counter").Value < 5 THEN
Msgbox DTSGlobalVariables("counter").Value
Set oPkg = DTSGlobalVariables.Parent
'Set previous step status to waiting.
oPkg.Steps("DTSStep_DTSActiveScriptTask_1").ExecutionStatus = _
DTSStepExecStat_Waiting
'Do not execute task 2, step 1 will restart.
Main = DTSStepScriptResult_DontExecuteTask
Else
'Execute task 2, do not restart step 1.
Main = DTSStepScriptResult_ExecuteTask
END IF
End Function