Library tutorials & articles
SQL Distributed Management Objects Part 2
- Introduction
- The Code
- The Job Steps
- The Job Schedule
- Tidying Up
The Job Schedule
Now, here comes the important part, the scheduling of the job, the job has been
created but now we have to schedule the job so that it runs at a specific date
and time.
JobSchedule object exposes the attributes of a single SQL Server Agent
executable job schedule. Dim oJobSchedule As SQLDMO.JobSchedule
Set oJobSchedule = New SQLDMO.JobSchedule
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'Schedule the task!
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
You can calculate any time and date for your task to start execution, it solely
depends on your choice or requirement. We have calculated the year, month and
day separately. Dim startyear, startmonth, startday
'Indicate execution scheduled for everyday by using
'the FrequencyType and FrequencyInterval properties.
oJobSchedule.Name = JobID
oJobSchedule.Schedule.FrequencyType = SQLDMOFreq_OneTime
We want to execute the task only once so we have set the frequency type to single
time.
'Set the ActiveStartDate to indicating the date on
'which the schedule becomes active. Start date is
'today's date
Dim mydate
mydate = DateAdd("h", CInt(Num_Of_Hours), Now())
Dim hr, min, sec
hr = Hour(mydate)
min = Minute(mydate)
sec = Second(mydate)
Dim mytime
mytime = hr & min & sec
startyear = DatePart("yyyy", mydate)
startmonth = DatePart("m", mydate)
startday = DatePart("d", mydate)
If Len(startmonth) < 2 Then startmonth = "0" & startmonth
If Len(startday) < 2 Then startday = "0" & startday
oJobSchedule.Schedule.ActiveStartDate = startyear & startmonth &
startday
Activestartdate property indicates the first effective date for a schedule. 'Set the ActiveStartTimeOfDay property to indicate the
'scheduled execution time on each day
oJobSchedule.Schedule.ActiveStartTimeOfDay = mytime
Activestarttimeofday property indicates the start time of the day for a schedule.
'Indicate that the schedule never expires
oJobSchedule.Schedule.ActiveEndDate = SQLDMO_NOENDDATE
oJobSchedule.Schedule.ActiveEndTimeOfDay = SQLDMO_NOENDTIME
Similarly, we have to provide the activeenddate and time for the job. We have
set these properties to SQLDMO_NOENDDATE and SQLDMO_NOENDTIME which means that
the job will never expire until is executed.
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
'Add task to scheduler
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
oJob.JobSchedules.Add oJobSchedule
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)
-
VB6 Runtime error 381 subsript out of range Error
by Uncle (2 replies)
-
passing and reading parameters from using Shell
by jigartoliya (0 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...
Events coming up
-
Nov
19
SQLBits V
Newport, United Kingdom
SQLBits is Europe's largest SQL Server conference, and SQLBits V will be the biggest and best yet. On November 19th we are holding a day of pre-conference seminars; on November 20th we have a pay-to-attend day of SQL Server 2008 and R2 content; and on Saturday November 21st we have our usual free community conference.
This thread is for discussions of SQL Distributed Management Objects Part 2.