Library tutorials & articles
SQL Distributed Management Objects Part 2
By S.S. Ahmed, published on 01 Nov 2001
Page 3 of 5
- Introduction
- The Code
- The Job Steps
- The Job Schedule
- Tidying Up
The Job Steps
We have created a new job step object in the statements above. The jobstep object
exposes the attributes of a single SQL Server agent executable job step. SQL
Server Agent jobs contain one or more execution units called steps. Each job
step contains a textual command, type of execution that specifies command interpretation,
and logic that determines the behaviour of the job if the step succeeds or fails
The subsystem property specifies the SQL Server Agent execution subsystem used to interpret job step task-defining text.
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.
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.
Add the individual job step to the jobsteps collection.
The applytotargetserver method adds an execution target to the list of targets maintained for the referenced SQL Server Agent job.
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.
Related articles
Related discussion
-
High-Performance .NET Application Development & Architecture
by Manjot Bawa (0 replies)
-
Permutations and combinations of multiple return codes
by actuszeus (1 replies)
-
dtPicker date format query
by konikula (1 replies)
-
VS.NET/sql server installation problem
by daspeac (4 replies)
-
Run-time error '91'
by converter2009 (1 replies)
Related podcasts
-
Stack Overflow: Podcast #28
This is the twenty-eighth episode of the StackOverflow podcast, where Joel and Jeff discuss Windows Azure, SQL Server 2008 full text search, Bayesian filtering, porn detection, and project management — among other things. Jeff met the inestimable Joey DeVilla aka Accordion Guy...
This thread is for discussions of SQL Distributed Management Objects Part 2.