Solved

vbs script to check MSSQLSERVER

Posted on 2013-10-24
2
227 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

705 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