{"id":310,"date":"2008-12-20T21:40:58","date_gmt":"2008-12-20T19:40:58","guid":{"rendered":"http:\/\/contoso.se\/blog\/?p=310"},"modified":"2010-09-01T12:26:52","modified_gmt":"2010-09-01T10:26:52","slug":"query-a-database-with-a-monitor","status":"publish","type":"post","link":"http:\/\/contoso.se\/blog\/?p=310","title":{"rendered":"Query a database with a monitor"},"content":{"rendered":"<p>I\u00c2\u00a0have seen a number of questions about how to run\u00c2\u00a0queries against a\u00c2\u00a0database and verify the answer. One way is to run a script inside a\u00c2\u00a0monitor. In <a href=\"http:\/\/contoso.se\/blog\/?p=305\">this<\/a> blog I wrote how to setup a script in a two state monitor. The script in this post\u00c2\u00a0will count number of\u00c2\u00a0 fields, if there are more then five, status of the monitor will be changed. Note that counting starts at\u00c2\u00a00 with fields collection.<\/p>\n<p>\u00c2\u00a0Const adOpenStatic = 3<br \/>\nConst adLockOptimistic = 3<\/p>\n<p>Set oAPI = CreateObject(&#8220;MOM.ScriptAPI&#8221;)<br \/>\nSet oBag = oAPI.CreatePropertyBag()<\/p>\n<p>Set objConnection = CreateObject(&#8220;ADODB.Connection&#8221;)<br \/>\nSet objRecordSet = CreateObject(&#8220;ADODB.Recordset&#8221;)<\/p>\n<p>objConnection.Open _<br \/>\n&#8220;Provider=SQLOLEDB;Data Source=R2B1;&#8221; &amp; _<br \/>\n&#8220;Trusted_Connection=Yes;Initial Catalog=ContosoConfiguration;&#8221; &amp; _<br \/>\n&#8220;User ID=CORP\\Administrator;Password=;&#8221;<\/p>\n<p>objRecordSet.Open &#8220;SELECT * FROM roles&#8221;, _<br \/>\nobjConnection, adOpenStatic, adLockOptimistic<\/p>\n<p>varNo = objRecordSet.Record.Count<\/p>\n<p>If varNO &gt; 5 Then<br \/>\nCall oBag.AddValue(&#8220;SQL_Status&#8221;,&#8221;Error&#8221;)<br \/>\nElse<br \/>\nCall oBag.AddValue(&#8220;SQL_Status&#8221;,&#8221;Ok&#8221;)<br \/>\nEnd If<\/p>\n<p>Call oAPI.Return(oBag)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u00c2\u00a0have seen a number of questions about how to run\u00c2\u00a0queries against a\u00c2\u00a0database and verify the answer. One way is to run a script inside a\u00c2\u00a0monitor. In this blog I wrote how to setup a script in a two state monitor. The script in this post\u00c2\u00a0will count number of\u00c2\u00a0 fields, if there are more then five, &hellip; <a href=\"http:\/\/contoso.se\/blog\/?p=310\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[13,19],"tags":[66,45,55,67],"_links":{"self":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/310"}],"collection":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=310"}],"version-history":[{"count":11,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/310\/revisions"}],"predecessor-version":[{"id":1345,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=\/wp\/v2\/posts\/310\/revisions\/1345"}],"wp:attachment":[{"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=310"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=310"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/contoso.se\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=310"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}