how to execute query from VBScript in script two state monitor SCOM

here is code :

'define and create objects for passing values in 2 state to SCOM
Dim oAPI, oBag
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oBag = oAPI.CreatePropertyBag()


StrConnect = "PROVIDER=SQLOLEDB.1;Integrated Security=SSPI;INITIAL CATALOG=DBName;DATA SOURCE=ServerName"
Set cnt = CreateObject("ADODB.Connection")
cnt.Open StrConnect

set recordSet = CreateObject("ADODB.Recordset")
SQLStr = " select * from .... "

recordSet.Open SQLStr, cnt,1,1

TotalRecords = recordSet.RecordCount

recordSet.Close : set recordSet = nothing
cnt.Close : set cnt = nothing

'We have to handle Status value from SCOM and create rule for each state
If TotalRecords >= 0 Then
Call oBag.AddValue("Status","ERROR")
Else
Call oBag.AddValue("Status","OK")
End If

Call oAPI.Return(oBag)

Comments

Post a Comment

Popular posts from this blog

Could not load file or assembly 'System.ServiceModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified at Configuration class initiation in CrmServiceHelper.cv

Exception caught instantiating TERADATA report server extension SQL Reporting Services

you face "ISV code aborted the operation" when you change status of the any record in Dynamics CRM 2013