tb
Programmer
- May 27, 2003
- 328
I have managed to find a way to execute certain tasks within a DTS package through code.
Most of the code examples only shows how to create new tasks and execute the entire package.
This code example will show you how to identify the task names and to execute them.
Hope someone will find this useful.
First of all you need to reference the Microsoft DTSPackage Object Library
Dim objPackage As DTS.Package2
Dim dtsresult As DTS.DTSTaskExecResult
Dim objEvent As Object
Dim objLog As Object
Dim iCount As Integer
'Instanciate the DTS package object
Set objPackage = New DTS.Package2
'Set the server/username/password and the DTS package to be run
objPackage.LoadFromSQLServer "Server IP Address", "UserName", "Password", DTSSQLStgFlag_Default, "", "", "", "DTS_Package_Name"
'Set Global variables
objPackage.GlobalVariables("BooleanValue").Value = True
objPackage.GlobalVariables("StringValue").Value = "This is my string value"
objPackage.GlobalVariables("DateValue").Value = Format(Now, "YYYY/MM/DD")
'Set object to raise an error on failure and to do eventlogs
objPackage.FailOnError = True
objPackage.WriteCompletionStatusToNTEventLog = True
'***************************************************
'This will only help you to identify the Task Names and to be taken out
For iCount = 1 To objPackage.Tasks.Count
Debug.Print objPackage.Tasks(iCount).Name
Next iCount
'***************************************************
'Execute the appropriate task
objPackage.Tasks("DTSTask_DTSActiveScriptTask_1").Execute objPackage, objEvent, objLog, dtsresult
objPackage.Tasks("DTSTask_DTSDataPumpTask_1").Execute objPackage, objEvent, objLog, dtsresult
objPackage.UnInitialize
'Mark objects for garbage collection
Set objPackage = Nothing
******************************************************
I found no explanation for the need for the following:
* objEvent
* objLog
BUT it is required parameters and the code works.
Have fun and hope to hear some comments ....
I was standing in the park, wondering why frisbees got bigger as they came closer... then it hit me!
Most of the code examples only shows how to create new tasks and execute the entire package.
This code example will show you how to identify the task names and to execute them.
Hope someone will find this useful.
First of all you need to reference the Microsoft DTSPackage Object Library
Dim objPackage As DTS.Package2
Dim dtsresult As DTS.DTSTaskExecResult
Dim objEvent As Object
Dim objLog As Object
Dim iCount As Integer
'Instanciate the DTS package object
Set objPackage = New DTS.Package2
'Set the server/username/password and the DTS package to be run
objPackage.LoadFromSQLServer "Server IP Address", "UserName", "Password", DTSSQLStgFlag_Default, "", "", "", "DTS_Package_Name"
'Set Global variables
objPackage.GlobalVariables("BooleanValue").Value = True
objPackage.GlobalVariables("StringValue").Value = "This is my string value"
objPackage.GlobalVariables("DateValue").Value = Format(Now, "YYYY/MM/DD")
'Set object to raise an error on failure and to do eventlogs
objPackage.FailOnError = True
objPackage.WriteCompletionStatusToNTEventLog = True
'***************************************************
'This will only help you to identify the Task Names and to be taken out
For iCount = 1 To objPackage.Tasks.Count
Debug.Print objPackage.Tasks(iCount).Name
Next iCount
'***************************************************
'Execute the appropriate task
objPackage.Tasks("DTSTask_DTSActiveScriptTask_1").Execute objPackage, objEvent, objLog, dtsresult
objPackage.Tasks("DTSTask_DTSDataPumpTask_1").Execute objPackage, objEvent, objLog, dtsresult
objPackage.UnInitialize
'Mark objects for garbage collection
Set objPackage = Nothing
******************************************************
I found no explanation for the need for the following:
* objEvent
* objLog
BUT it is required parameters and the code works.
Have fun and hope to hear some comments ....
I was standing in the park, wondering why frisbees got bigger as they came closer... then it hit me!