Library tutorials & articles
SQL Distributed Management Objects Part 2
The Code
Now, lets go through the code step by step:
Private Sub Class_Initialize()
On Error Resume Next
NL = Chr$(13) & Chr$(10)
Set oSQLServer = New SQLDMO.SQLServer
oSQLServer.LoginTimeout = 10
End Sub
The main object is created when the class is initialized, similarly this object shall be deleted from the memory when the class is terminated.
Our main method is known as AddTask, this method will add a new task to the task scheduler, note we have not passed the parameters directly to function instead we have used the properties to get the input from the user.
Public Function AddTask()
On Error GoTo errhandler
oSQLServer.DisConnect
Disconnect the server if its already connected.
If Server = "" Then
ErrDesc = "You must enter server name."
Exit Function
ElseIf UserID = "" Then
ErrDesc = "You must enter a valid User ID"
Exit Function
ElseIf Password = "" Then
Password = ""
End If
Get values of important parameters from the user, these values are needed to
connect to the sqlserver. 'Connect to the server!
oSQLServer.Connect CStr(Server), CStr(UserID), CStr(Password)
Dim oJob As New SQLDMO.Job
Dim idStep As Integer
Idstep will be used to define the total number of steps to be included in the
task. 'Set the schedule name
oJob.Name = JobID
Assign a name to the job. 'objSQLServer.Executive.Tasks.Add oJob
oSQLServer.JobServer.Jobs.Add oJob
Add the newly created job to the job server. The jobserver object exposes attributes
associated with SQL server agent. SQL Server agent is responsible for executing
the scheduled jobs and notifying operators of SQL Server error conditions or
other SQL Server execution or job states. 'Use the code below to change the task!!!
oJob.BeginAlter
'idStep = 0
Initially we have assigned a zero value to the step id. Because we intend to
add two steps in our task, so we run a loop twice. For idStep = 0 To 2
Dim oJobStep As SQLDMO.JobStep
Set oJobStep = New SQLDMO.JobStep
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.