我试图从我的 VBScript 返回两个值并将它们存储在单独的属性包中:
包含
If
条件的结果Call oBag.AddValue("Status","Bad") Call objAPI.AddItem(oBag) Else Call oBag.AddValue("Status","Good") Call objAPI.AddItem(oBag)
包含已执行的 SQL 查询的输出
Call oBag.AddValue("Count",objRS.Fields("CountStuff")) Call objAPI.AddItem(oBag)
用于传递到 SCOM 旁边。
但是在调试时,我收到以下错误:
(41,1) ADODB.Field:BOF 或 EOF 为 True,或者当前记录已被删除。请求的操作需要当前记录。
这是完整的 VBScript:
Dim objCN, strConnection
Dim objAPI, oBag
Set objCN = CreateObject("ADODB.Connection")
Set objAPI = CreateObject("MOM.ScriptAPI")
Set oBag = objAPI.CreateTypedPropertyBag(2)
strConnection = "Driver={SQL Server};Server=SCOMSRVDB01,2880;Database=DBABee;Trusted_Connection=TRUE"
objCN.Open strConnection
Dim strSQLQuery
strSQLQuery = "Select COUNT (*) as CountStuff from sys.objects"
Dim objRS
Set objRS = CreateObject("ADODB.Recordset")
Set objRS = objCN.Execute(strSQLQuery)
'WScript.Echo (objRS.Fields("CountStuff"))
Call oBag.AddValue("Count", objRS.Fields("CountStuff"))
Call objAPI.AddItem(oBag)
Do Until objRS.EOF
'WScript.Echo objRS.Fields("CountStuff")
If objRS.Fields("CountStuff") > 0 Then
'WScript.Echo "evaluated as bad"
Call oBag.AddValue("Status","Bad")
Call objAPI.AddItem(oBag)
Else
Call oBag.AddValue("Status","Good")
Call objAPI.AddItem(oBag)
End If
objRS.MoveNext
Loop
Call objAPI.ReturnItems
objRS.Close
'Property[@Name='Status']