Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 26th, 2007, 09:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default Creating Job with VBScript in it Fails

I am not sure if I am so exhausted, that I don't find anything wrong with this though it runs fine from command prompt using cscript, still it is playing with my time by not creating the job giving this error.
Error 14277: The command script does not destroy all the objects that it creates. Revise the command script. The job was not saved.
I have similar other steps with vbscripts working fine. But still this kills my time. Can anyone see if I am doing something wrong with this code.

This script basically starts an application and verifies if its child processes are running fine, else sends out an email with error.

The ones in BLUE are the objects created, and the ones BLUE are the objects destroyed.
Code:
Dim StrComputer, StrSql, Con, ConStr, RS, objWMIService, colProcessList, iRow, iCol, ArrRowSet
Dim Wshshell, StrCmd, RetCode
StrComputer = "."
Set Con = CreateObject("adodb.connection")
ConStr = "Provider=sqloledb;Data Source=localhost;Initial Catalog=SOMEDB;User Id=xyz;Password=xyz;"
Con.Open ConStr
StrSql = "SELECT AppName FROM mytable ORDER BY StartupSeqID"
Set RS = Con.Execute(StrSql)
ArrRowSet = RS.GetRows()
Set Con = Nothing
Set RS = Nothing

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & StrComputer & "\root\cimv2")
Set Wshshell = WScript.CreateObject("wscript.shell")
StrCmd = """C:\Program Files\someapp.exe"""
RetCode = Wshshell.run(StrCmd, 1, FALSE)
WScript.Sleep(5000)
If RetCode = 0 Then
'Verify the relevant child processes of this app
    For iRow = LBound(ArrRowSet, 2) To UBound(ArrRowSet, 2) 
        For iCol = LBound(ArrRowSet, 1) To UBound(ArrRowSet, 1)
            Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & ArrRowSet(iCol, iRow) & "'")
            For Each objProcess in colProcessList
                If UCase(objProcess.Name) <> UCase(ArrRowSet(iCol, iRow)) Then 
                    SendErrorMail ArrRowSet(iCol, iRow)
                End If
            Next
            Set colProcessList = Nothing
        Next
    Next
End If

Set objWMIService = Nothing
Set Wshshell = Nothing

Function SendErrorMail (strAppName)
    Dim objNet, objCDOMail, strBody, strTo, strSubject, strCC, strComputerName
    strTo =  "me@myid.com"
    Set objNet = CreateObject("WScript.NetWork")
    strComputerName = objNet.ComputerName
    Set objNet = Nothing
    strSubject = "some subject"
    strBody =  strBody & "some body message"
    Set objCDOMail = CreateObject("CDO.Message")
        objCDOMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        objCDOMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
        objCDOMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        objCDOMail.Configuration.Fields.Update 
        objCDOMail.From    = strComputerName
        objCDOMail.To      = strTo
        objCDOMail.CC      = strCC
        objCDOMail.Bcc     = strBcc
        objCDOMail.Subject = strSubject
        objCDOMail.TextBody    = strBody
        objCDOMail.Send
    Set objCDOMail = Nothing
End Function
Cheers.

_________________________
- Vijay G
Strive for Perfection
__________________
- Vijay G
 
Old April 27th, 2007, 02:56 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Some sleep last night gave me some energy to get through this. I was writing a function/sub there for the email code. When I removed the function and put that code within the main code it worked.

Anyways, thanks for your time in reading this.
Cheers.

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i get a job as a programmer while in H.S.? iceman90289 C# 2005 10 March 27th, 2008 08:43 PM
Job Fails - trying to insert into remote machine happygv SQL Server 2000 0 March 8th, 2007 10:03 AM
job for experts g_tufat Need help with your homework? 0 July 3rd, 2006 05:49 PM
Job fails & need to use domain\user acct to run kiwikencox SQL Server 2000 1 October 17th, 2005 09:30 PM
DB backup Job fails within a second or two happygv SQL Server 2000 6 October 16th, 2004 01:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.