January 17, 2002 at 10:16 am
Hi
I am only a beginner at DMO.
I have tried to remove a backup job using the code below without success. Can anyone see what I have done wrong or suggest an alternative method.
Private Sub cmdDelete_Click()
Dim i As Integer
Dim j As Integer
Dim iCount As Integer
Dim oSQLServer As SQLDMO.SQLServer
Dim oJobserver As SQLDMO.JobServer
Dim oJob As SQLDMO.Job
Dim sSysJob() As String
Dim sSysJobSch() As String
Dim sDelName As String
sDelName = lstJob.Text
Set oSQLServer = New SQLDMO.SQLServer
With oSQLServer
.LoginSecure = True
.Connect nldbServer$
End With
'delete backup job highlighted in list box
oJobserver.Jobs.Remove (sDelName)
lstJob.Clear
lstJobSch.Clear
'refresh backup jobs list
Set oJobserver = oSQLServer.JobServer
Set oJob = New SQLDMO.Job
If oJobserver.Jobs.count = 0 Then
ReDim sSysJob(0 To 0)
sSysJob(0) = ""
sListBJob = sSysJob
ReDim sSysJobSch(0 To 0)
sSysJobSch(0) = ""
sListBJobSch = sSysJobSch
Else
ReDim sSysJob(0 To Jobserver.Jobs.count - 1)
ReDim sSysJobSch(0 To oJobserver.Jobs.count - 1)
For i = 1 To oJobserver.Jobs.count
sSysJob(iCount) = oJobserver.Jobs(i).Name
sSysJobSch(iCount) = oJobserver.Jobs(i).Description
iCount = iCount + 1
Next
sListBJob = sSysJob
sListBJobSch = sSysJobSch
End If
Set oJob = Nothing
Set oJobserver = Nothing
Set oSQLServer = Nothing
For j = 0 To UBound(sListBJob)
lstJob.AddItem sListBJob(j)
lstJobSch.AddItem sListBJobSch(j)
Next
End Sub
Many Thanks in anticipation
Chan
January 17, 2002 at 4:51 pm
You dont want to actually delete the job, just remove it from the listbox? You dont need to put the stuff into an array before adding it either, should be able to add it directly.
Andy
January 18, 2002 at 2:30 am
Hi Andy
Thanks for your quick reply.
Yes I would like to delete the job instead of removing it from the listbox. So when then datbase adiministrator looks at things using EM then they will see all the jobs that are being used.
Chan
quote:
You dont want to actually delete the job, just remove it from the listbox? You dont need to put the stuff into an array before adding it either, should be able to add it directly.Andy
January 18, 2002 at 9:40 pm
Might be a documentation error. According to the class browser the parameter of the remove method must be a long.
As an alternative replace your line
oJobserver.Jobs.Remove (sDelName)
with
Set oJobserver = oSQLServer.JobServer
oJobserver.Jobs("test").Remove
January 21, 2002 at 2:36 am
thanks Leon
Those new lines worked.
Chan
quote:
Might be a documentation error. According to the class browser the parameter of the remove method must be a long.As an alternative replace your line
oJobserver.Jobs.Remove (sDelName)
with
Set oJobserver = oSQLServer.JobServer
oJobserver.Jobs("test").Remove
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply