idStep = idStep + 1
oJobStep.Name = JobID & idStep
oJobStep.StepID = idStep
'Set the job step executable subsystem.
oJobStep.SubSystem = "TSQL"
The subsystem property specifies the SQL Server Agent execution subsystem used to interpret job step task-defining text.
If DatabaseName <> "" Then
oJobStep.DatabaseName = DatabaseName
Else
oJobStep.DatabaseName = "yourdatabase"
End If
If the user fails to pass the database name from the front end than the component will pick up the hardcoded database name provided that you have hardcoded the database name in your code.
If idStep = "1" Then
If CommandText <> "" Then
oJobStep.Command = CommandText
Else
oJobStep.Command = "select
* from table1"
oJobStep.OnSuccessAction
= SQLDMOJobStepAction_GotoNextStep
End If
Else
oJobStep.StepID = 2
If Commandtext2 <> "" Then
oJobStep.Command = Commandtext2
Else
oJobStep.Command = "delete
from table2"
oJobStep.OnSuccessAction
= SQLDMOJobStepAction_QuitWithSuccess
End If
End If
We have added two commands to the jobs, one will return all the records from the table and the second will delete all the records from the particular table, this has been done just to give you an example, you can do whatever you want with your database tables by passing the command text either from the front end or by hardcoding the command text in the code as seen above.
oJob.JobSteps.Add oJobStep
Next
Add the individual job step to the jobsteps collection.
'Set the Target Server
oJob.ApplyToTargetServer (CStr(Server))
The applytotargetserver method adds an execution target to the list of targets maintained for the referenced SQL Server Agent job.
Comments