Solved

vbs script to check MSSQLSERVER

Posted on 2013-10-24
2
223 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

809 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