Solved

vbs script to check MSSQLSERVER

Posted on 2013-10-24
2
220 Views
Last Modified: 2013-11-01
I have the following script running as a scheduled task (has been running for over a year)

(note: computer/email names changed for security)

Set objComputer = GetObject("WinNT://test123,computer")
objComputer.Filter = Array("Service")
            Dim iMsg
            Dim iConf
            Dim Flds
            Dim strHTML
            Dim strSmartHost

            Const cdoSendUsingPort = 2
            StrSmartHost = "mail.test.local"

            set iMsg = CreateObject("CDO.Message")
            set iConf = CreateObject("CDO.Configuration")

            Set Flds = iConf.Fields


            With Flds
                  .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = cdoSendUsingPort
                  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSmartHost
                  .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
                  .Update
            End With
For Each aService In objComputer
      select case aService.Name
            case "MSSQLSERVER"
                  if aService.Status <> 4 then
      
                        With iMsg
                              Set .Configuration = iConf
                              .To = "IT@elgin.com"
                              .From = "Webdbadmin@elgin.com"
                              .Subject = "The SQL Server on test123 is not running!"
                              .TextBody = "SQL Server is not running. ."
                              .Send
                        End With
            
                  end if

                  end select
      
Next

      Set iMsg = Nothing
      Set iConf = Nothing
      Set Flds = Nothing


We started receiving the message saying it is not running when it is

Any one have ideas as to why the false negative?
0
Comment
Question by:johnnyg123
2 Comments
 
LVL 39

Expert Comment

by:lcohan
ID: 39598233
I suggest you add more areas to the Topic (and tags) as this is not (purely) a MS SQL Server question in my opinion.
0
 
LVL 12

Accepted Solution

by:
Seaton007 earned 500 total points
ID: 39598347
Does this script run locally on the SQL server, or does it run on a remote machine?

Also, it could be that the service had issues, the email was sent, the issues resolved themselves, then somebody checked on the server and found no issues.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Suggested Solutions

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now