<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SQL Agent on Andy M Mallon - AM²</title><link>https://am2.co/tag/sql-agent/</link><description>Recent content in SQL Agent on Andy M Mallon - AM²</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Fri, 07 Mar 2025 16:17:43 -0500</lastBuildDate><atom:link href="https://am2.co/tag/sql-agent/index.xml" rel="self" type="application/rss+xml"/><item><title>Consuming SQL Agent dates &amp; durations</title><link>https://am2.co/2025/03/07/consuming-sql-agent-dates-durations/</link><pubDate>Fri, 07 Mar 2025 16:17:43 -0500</pubDate><guid>https://am2.co/2025/03/07/consuming-sql-agent-dates-durations/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=vBynw9Isr28"&gt;&lt;img src="https://am2.co/wp-content/uploads/StopWatch-300x300.png" alt="" width="300" height="300" class="alignright size-medium wp-image-57887" /&gt;&lt;/a&gt;&#10;SQL Agent&amp;rsquo;s schema is older than me. It handles dates, times, and durations like it&amp;rsquo;s 1980 by using integers instead of date/time data types. My buddy Aaron Bertrand talks more about &lt;a href="https://sqlblog.org/dates" target="_blank"&gt;Dating Responsibly&lt;/a&gt; so that you can have a good datetime with your own database.&lt;/p&gt;</description></item><item><title>Job to stop other job at specific time</title><link>https://am2.co/2021/08/13/job-to-stop-other-job-at-specific-time/</link><pubDate>Fri, 13 Aug 2021 11:25:34 -0400</pubDate><guid>https://am2.co/2021/08/13/job-to-stop-other-job-at-specific-time/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/298011/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;We have a job which imports data daily from a remote SQL Server every night, I'll call it Import-Job. Most of the time this job runs through in about 15 minutes and everything is fine but due to a rather unstable VPN connection sometimes the job takes a lot more time.&lt;/p&gt;</description></item><item><title>Why putting SQL Agent offline caused WSFC to fail over on passive node?</title><link>https://am2.co/2021/08/12/why-putting-sql-agent-offline-caused-wsfc-to-fail-over-on-passive-node/</link><pubDate>Thu, 12 Aug 2021 23:17:20 -0400</pubDate><guid>https://am2.co/2021/08/12/why-putting-sql-agent-offline-caused-wsfc-to-fail-over-on-passive-node/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/297983/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have 2 node Windows Failover Cluster with Quorum disk.&#10;SQL agent is NOT a resource of the cluster.&lt;/p&gt;&#10;&lt;p&gt;I needed to enable service broker on the server; for that I need to set SQL Agent offline, run tsql statement then simply put it back online.&lt;/p&gt;</description></item><item><title>sp_update_schedule says @schedule_id does not exist</title><link>https://am2.co/2020/10/06/sp_update_schedule-says-schedule_id-does-not-exist/</link><pubDate>Tue, 06 Oct 2020 12:53:39 -0400</pubDate><guid>https://am2.co/2020/10/06/sp_update_schedule-says-schedule_id-does-not-exist/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/276609/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I wrote a script that reads job schedules from &lt;code&gt;msdb.dbo.sysschedules&lt;/code&gt; and runs &lt;code&gt;sp_update_schedule&lt;/code&gt; to change the &lt;code&gt;active_start_time&lt;/code&gt; for a given subset of jobs. In each case, &lt;code&gt;sp_update_schedule&lt;/code&gt; fails with the message &amp;quot;The specified @schedule_id('xxx') does not exist&amp;quot;. (MessageID 14262, Severity 16)&lt;/p&gt;</description></item><item><title>Fixing tempdb: Growing, shrinking, and removing data files</title><link>https://am2.co/2020/04/21/fixing-tempdb/</link><pubDate>Tue, 21 Apr 2020 09:00:37 -0400</pubDate><guid>https://am2.co/2020/04/21/fixing-tempdb/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:500px"&gt;&lt;a href="https://www.youtube.com/watch?v=RaCodgL9cvk"&gt;&lt;img src="https://am2.co/wp-content/uploads/drop-files-here-extra.jpg" alt="" width="500" height="224" class="size-full wp-image-3070" /&gt;&lt;/a&gt; Dropping tempdb files like they're hot&lt;/figure&gt;&#10;&lt;p&gt;I recently came across a server where &lt;code&gt;tempdb&lt;/code&gt; was breaking all the rules.&lt;/p&gt;&#10;&lt;ul&gt;&#10;&#9;&lt;li&gt;Data files were all different sizes. I want all data files to be the same size so that proportional fill uses them evenly.&lt;/li&gt;&#10;&#9;&lt;li&gt;There were 10 &lt;code&gt;tempdb&lt;/code&gt; files, with 8 files on a dedicated disk, and 2 on a slower disk shared with other data files. And free space was sky high, so the extra files aren't needed anymore! (They were probably added to fix a short-term emergency, and never cleaned up.)&lt;/li&gt;&#10;&#9;&lt;li&gt;The log file was tiny, and didn't have room to grow. For a 500GB tempdb, the log file was only 4GB!&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="three-fixes"&gt;Three fixes&lt;/h2&gt;&#10;&lt;p&gt;There are three problems I&amp;rsquo;ve got to fix. I need to (1) remove those two extra files, (2) grow the &lt;code&gt;tempdb&lt;/code&gt; log file, and (3) even out the size of the data files (and shrink them a little to make room for the larger log file. We&amp;rsquo;re going to tackle these in the reverse order than I listed them&amp;ndash;partially out of necessity, and partially because it&amp;rsquo;s going to be easier.&lt;/p&gt;</description></item><item><title>Troubleshooting Powershell errors from SQL Agent job</title><link>https://am2.co/2017/04/19/troubleshooting-powershell-errors-from-sql-agent-job/</link><pubDate>Wed, 19 Apr 2017 13:29:54 -0400</pubDate><guid>https://am2.co/2017/04/19/troubleshooting-powershell-errors-from-sql-agent-job/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/171395/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have a powershell script that I am trying to add in to a sql agent job, but the job step is failing with the following error&lt;/p&gt;&#10;&lt;div class="errorMsg"&gt;&#10;A job step received an error at line 1 in a PowerShell script. The corresponding line is 'import-module SQLPS -DisableNameChecking'. Correct the script and reschedule the job. The error information returned by PowerShell is: 'Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft SQL Server\130\Tools\PowerShell\Modules\SQLPS\Microsoft.SqlServer.Management.PSSnapins.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.&#10;&lt;/div&gt;&#10;&lt;p&gt;I assumed that the error was being caused by differences in the module path, so I explicitly set the path via $env:PSModulePath to match the path of my powershell session where the code runs fine. I am pretty new to powershell, so any help you could provide would be appreciated&lt;/p&gt;</description></item><item><title>SQL Agent Job Logs - Can't get the Error Log</title><link>https://am2.co/2017/01/25/sql-agent-job-logs-cant-get-the-error-log/</link><pubDate>Wed, 25 Jan 2017 09:59:18 -0500</pubDate><guid>https://am2.co/2017/01/25/sql-agent-job-logs-cant-get-the-error-log/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/177204/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I've some logs that I want to extract to a report in order to get the SQL_Agent_Jobs status that runs during the night. If the Job fails then I want to receive the Error Log in a table. I am trying to get that information with this query:&lt;/p&gt;</description></item><item><title>xp_sqlagent_enum_jobs alternative</title><link>https://am2.co/2016/02/18/xp_sqlagent_enum_jobs_alt/</link><pubDate>Thu, 18 Feb 2016 10:00:21 -0500</pubDate><guid>https://am2.co/2016/02/18/xp_sqlagent_enum_jobs_alt/</guid><description>&lt;h3&gt;What's &lt;code&gt;xp_sqlagent_enum_jobs&lt;/code&gt;?&lt;/h3&gt;&#10;If you landed on this post, I'm guessing you know the answer to this, so I'll be quick. `xp_sqlagent_enum_jobs` is an undocumented (and thus, unsupported) extended procedure that gives information on whether a job is currently running, when it last ran, when it runs next, etc.&#10;&lt;p&gt;The supported alternative is to use &lt;code&gt;sp_help_job&lt;/code&gt; (which calls &lt;code&gt;xp_sqlagent_enum_jobs&lt;/code&gt;), but &lt;code&gt;sp_help_job&lt;/code&gt; is difficult to use in automation because trying to do &lt;code&gt;INSERT #temp EXEC sp_help_job;&lt;/code&gt; will result in an error due to nested &lt;code&gt;INSERT...EXEC&lt;/code&gt; statements (Error 8164: &amp;ldquo;An INSERT EXEC statement cannot be nested.&amp;rdquo;). As a result, people often turn to calling the unsupported xp directly.&lt;/p&gt;</description></item><item><title>Really Long Descriptions on SQL Agent Jobs</title><link>https://am2.co/2015/09/25/really-long-descriptions-on-sql-agent-jobs/</link><pubDate>Fri, 25 Sep 2015 14:38:00 -0400</pubDate><guid>https://am2.co/2015/09/25/really-long-descriptions-on-sql-agent-jobs/</guid><description>&lt;h3 id="warning-silent-truncation-ahead"&gt;WARNING: Silent truncation ahead&lt;/h3&gt;&#10;&lt;p&gt;Have you ever tried to enter a really long description on a SQL Agent job?&lt;/p&gt;&#10;&lt;p&gt;Maybe you were trying to put some sort of warning to people who might be trying to edit the job, or triage info for when the job fails. (Ok, so this sort of documentation should be on your wiki, not in a job description&amp;hellip; but stuff happens)&lt;/p&gt;</description></item><item><title>Using SQL Agent MSX for Availability Groups</title><link>https://am2.co/2015/07/07/using-sql-agent-msx-for-availability-groups/</link><pubDate>Tue, 07 Jul 2015 00:22:00 -0400</pubDate><guid>https://am2.co/2015/07/07/using-sql-agent-msx-for-availability-groups/</guid><description>&lt;img src="https://am2.co/wp-content/uploads/13195035-887b-4719-bd2d-63e7ac4d8f88-large11.jpg" alt="" width="450" height="316" class="alignright size-full wp-image-564" /&gt;&#10;Availability Groups (AGs) are all the rage these days. Every SQL Saturday, every local Users Group, bloggers and DBAs everywhere are all talking about how cool they are. There's a lot of talk about how AGs provide a compelling alternative to Failover Cluster Instances (FCIs). The cost (nothing is free, of course) is that with AGs, you have non-contained objects that you need to manually keep in sync between nodes.&#10;&lt;p&gt;A lot has been said and blogged about syncing non-contained objects. &lt;a href="https://www.sqlskills.com/blogs/jonathan/synchronize-availability-group-logins-and-jobs/" target="_blank" rel="noopener noreferrer"&gt;Here&lt;/a&gt;. &lt;a href="http://sqlmag.com/blog/alwayson-availability-groups-and-sql-server-jobs-part-4-synchronizing-server-level-details" target="_blank" rel="noopener noreferrer"&gt;Here&lt;/a&gt;. &lt;a href="http://www.brentozar.com/archive/2014/11/change-alwayson-availability-groups/" target="_blank" rel="noopener noreferrer"&gt;Here&lt;/a&gt;. &lt;a href="https://sql2012alwaysonlogin.codeplex.com/" target="_blank" rel="noopener noreferrer"&gt;Here&lt;/a&gt;. And plenty of other places.&lt;/p&gt;</description></item></channel></rss>