{"id":862,"date":"2006-04-25T11:32:00","date_gmt":"2006-04-25T11:32:00","guid":{"rendered":"\/blogs\/bobb\/post\/Using-WMI-and-SQL-Agent-Alerts-(part-2).aspx"},"modified":"2013-01-04T00:00:15","modified_gmt":"2013-01-04T08:00:15","slug":"using-wmi-and-sql-agent-alerts-part-2","status":"publish","type":"post","link":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/","title":{"rendered":"Using WMI and SQL Agent Alerts (part 2)"},"content":{"rendered":"<p>\nThis one ought to be titled &quot;Your error message is such a tease&quot;.\n<\/p>\n<p>\nI&#39;ve always liked the fact that SQL Server 2005 error messages&nbsp;are verbose (modulo security considerations for login error for example). I always point out at least one during classes, start to read the message&#8230;and about 50 words or so later, tell students to &quot;check out the entire text of the message offline&quot;. Excellent! Of course message boxes in applications&nbsp;that display these verbose errors&nbsp;must be made bigger or scrollbars added. Such is life.\n<\/p>\n<p>\nSo, in SP1, my perfectly working WMI alerts stopped working. Looking at the job history, I found the following:\n<\/p>\n<p>\nUnable to start execution of step 1 (reason: The job step contains one or more tokens. For SQL Server 2005 Service Pack 1 or later, all job steps with tokens must be updated with a macro before the job can run.). The step failed.\n<\/p>\n<p>\nGreat. Except what&#39;s the magic macro??? What a tease, everything I need to fix things except for the most vital piece of info. Downloaded the <a href=\"http:\/\/www.microsoft.com\/en-us\/download\/details.aspx?id=4152\">April Books Online update<\/a>, which had a TON of great new and revised content. But nothing about this problem (well they can&#39;t catch everything right away). Then I remembered RTF-readme file. Went to the latest &quot;<a href=\"http:\/\/support.microsoft.com\/kb\/913090\/en-us\" class=\"broken_link\">KB 913090 <\/a>&#8211; A List of bugs that have been been fixed&quot; and found IT had been updated with a reference to &quot;<a href=\"http:\/\/support.microsoft.com\/kb\/915845\/en-us\">KB 915845 <\/a>&#8211; SQL Server Agent jobs fail when the jobs contain job steps that use tokens after you install SQL Server 2005 Service Pack 1&quot;. Yep that&#39;s the one!! The magic macros are:\n<\/p>\n<p>\n$(ESCAPE_SQUOTE(token))<br \/>\n$(ESCAPE_DQUOTE(token))<br \/>\n$(ESCAPE_RBRACKET(token))<br \/>\n$(ESCAPE_NONE(token))\n<\/p>\n<p>\nThere&#39;s even a nice script that catalogs a procedure to update your existing jobs. What could be easier? Except, attempting to catalog the procedure yields &quot;A fatal scripting error occurred. Incorrect syntax occured while parsing &#39;. Huh? That&#39;s too sparse of an error. What now, the saga continues&#8230;.\n<\/p>\n<p>\nTurns out this error occurred because I had SSMS working&nbsp;in SQLCMD mode by default (see &quot;<a href=\"\/blogs\/bobb\/#a8846a7e1-9531-48e4-b54e-c4eac6fd216f\" class=\"broken_link\">What&#39;s fixed in SP1 blog entry<\/a>&quot;) and because there was a token $anything in the code, it was being processed by SQLCMD. Ohhhh. Turned off SQLCMD mode and it worked fine. Jobs fixed and working. The jobstep SQL now looks like this:\n<\/p>\n<p>\nINSERT INTO DeadlockEvents(AlertTime, DeadlockGraph)<br \/>\n&nbsp; VALUES (getdate(), N&#39;$(ESCAPE_NONE(WMI(TextData)))&#39;)\n<\/p>\n<p>\nSo that&#39;s &quot;the whole story&quot;. Hope it saves you some grief. That said, I REALLY like the WMI and Event Notification idea a lot. It&#39;s like having the database &quot;tell me&quot; when there&#39;s a problem that I want to know about. In real-time or queued and saved as I sleep for resolution &quot;at my leisure&quot;. My leisure&#8230;ha, how about &quot;the next morning&quot;? I&#39;ll take that.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This one ought to be titled &quot;Your error message is such a tease&quot;. I&#39;ve always liked the fact that SQL Server 2005 error messages&nbsp;are verbose (modulo security considerations for login error for example). I always point out at least one during classes, start to read the message&#8230;and about 50 words or so later, tell students [&hellip;]<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,28],"tags":[],"class_list":["post-862","post","type-post","status-publish","format-standard","hentry","category-event-notifications","category-sql-server-2005"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.9.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using WMI and SQL Agent Alerts (part 2) - Bob Beauchemin<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using WMI and SQL Agent Alerts (part 2) - Bob Beauchemin\" \/>\n<meta property=\"og:description\" content=\"This one ought to be titled &quot;Your error message is such a tease&quot;. I&#039;ve always liked the fact that SQL Server 2005 error messages&nbsp;are verbose (modulo security considerations for login error for example). I always point out at least one during classes, start to read the message&#8230;and about 50 words or so later, tell students [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Bob Beauchemin\" \/>\n<meta property=\"article:published_time\" content=\"2006-04-25T11:32:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-01-04T08:00:15+00:00\" \/>\n<meta name=\"author\" content=\"Bob Beauchemin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bob Beauchemin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/\",\"name\":\"Using WMI and SQL Agent Alerts (part 2) - Bob Beauchemin\",\"isPartOf\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\"},\"datePublished\":\"2006-04-25T11:32:00+00:00\",\"dateModified\":\"2013-01-04T08:00:15+00:00\",\"author\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Event Notifications\",\"item\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/event-notifications\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using WMI and SQL Agent Alerts (part 2)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website\",\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/\",\"name\":\"Bob Beauchemin\",\"description\":\"SQL Server Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e\",\"name\":\"Bob Beauchemin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g\",\"caption\":\"Bob Beauchemin\"},\"sameAs\":[\"http:\/www.sqlskills.com\/blogs\/bobb\/\"],\"url\":\"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using WMI and SQL Agent Alerts (part 2) - Bob Beauchemin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/","og_locale":"en_US","og_type":"article","og_title":"Using WMI and SQL Agent Alerts (part 2) - Bob Beauchemin","og_description":"This one ought to be titled &quot;Your error message is such a tease&quot;. I&#39;ve always liked the fact that SQL Server 2005 error messages&nbsp;are verbose (modulo security considerations for login error for example). I always point out at least one during classes, start to read the message&#8230;and about 50 words or so later, tell students [&hellip;]","og_url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/","og_site_name":"Bob Beauchemin","article_published_time":"2006-04-25T11:32:00+00:00","article_modified_time":"2013-01-04T08:00:15+00:00","author":"Bob Beauchemin","twitter_misc":{"Written by":"Bob Beauchemin","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/","name":"Using WMI and SQL Agent Alerts (part 2) - Bob Beauchemin","isPartOf":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website"},"datePublished":"2006-04-25T11:32:00+00:00","dateModified":"2013-01-04T08:00:15+00:00","author":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e"},"breadcrumb":{"@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/using-wmi-and-sql-agent-alerts-part-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/"},{"@type":"ListItem","position":2,"name":"Event Notifications","item":"https:\/\/www.sqlskills.com\/blogs\/bobb\/category\/event-notifications\/"},{"@type":"ListItem","position":3,"name":"Using WMI and SQL Agent Alerts (part 2)"}]},{"@type":"WebSite","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#website","url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/","name":"Bob Beauchemin","description":"SQL Server Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.sqlskills.com\/blogs\/bobb\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/62bfa986c5b5d28fcffd8b4fc409c73e","name":"Bob Beauchemin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.sqlskills.com\/blogs\/bobb\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6f80e6cc667410857fa6a21931dc528b8092f4d112bf7a8ff7c267674d44ee37?s=96&d=mm&r=g","caption":"Bob Beauchemin"},"sameAs":["http:\/www.sqlskills.com\/blogs\/bobb\/"],"url":"https:\/\/www.sqlskills.com\/blogs\/bobb\/author\/bobb\/"}]}},"_links":{"self":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/comments?post=862"}],"version-history":[{"count":0,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/posts\/862\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/media?parent=862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/categories?post=862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sqlskills.com\/blogs\/bobb\/wp-json\/wp\/v2\/tags?post=862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}