<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Return to LifeAsBob - SQL Server | SQL Agent</title>
    <link>http://www.lifeasbob.com/</link>
    <description>Horkay Blog</description>
    <language>en-us</language>
    <copyright>Robert J. Horkay</copyright>
    <lastBuildDate>Wed, 24 Jun 2009 15:43:24 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>bobh@lifeasbob.com</managingEditor>
    <webMaster>bobh@lifeasbob.com</webMaster>
    <item>
      <trackback:ping>http://www.lifeasbob.com/Trackback.aspx?guid=40a43d05-603c-40e4-9a31-6f3c369c2e1f</trackback:ping>
      <pingback:server>http://www.lifeasbob.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.lifeasbob.com/PermaLink,guid,40a43d05-603c-40e4-9a31-6f3c369c2e1f.aspx</pingback:target>
      <dc:creator>Bob Admin</dc:creator>
      <wfw:comment>http://www.lifeasbob.com/CommentView,guid,40a43d05-603c-40e4-9a31-6f3c369c2e1f.aspx</wfw:comment>
      <wfw:commentRss>http://www.lifeasbob.com/SyndicationService.asmx/GetEntryCommentsRss?guid=40a43d05-603c-40e4-9a31-6f3c369c2e1f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This script copies jobs from one msdb database to another, useful for when SQL Server
is re-installed, and the DBA Forgot to script out the sql agent jobs; but you still
have the old msdb mdf and ldf.  
</p>
        <p>
Simply attach the database as msdb_old.
</p>
        <p>
It is also possible to use this via a linked server and copy some sqlagent jobs from
one server to another; this script is specific to sql server 2005.  
</p>
        <p>
One item I had to adjust is that some of the jobs appeared "greyed" out afterwards
and I had to open each job and adjust the target server to "local".  
</p>
        <p>
But it was still quicker than re-creating all the jobs.  (I was unable to restore
the previous version of the msdb database because it was at a lower service pack level
than what the new server was built at - had I been smart as the new server was built
there would have been a restore of the msdb database completed when the new server
was at the same level, but I missed that step and was then left with the task of recreating
all the jobs, argh).
</p>
        <p>
I'd be cautious using this script if there were a lot of reporting subscription jobs
(as there would have to be some synchronizations with the report database and website),
but in this particular case all the jobs were custom backups, tlogs, exports, imports
and other purely tsql and ssis related tasks.
</p>
        <p>
          <a href="http://www.lifeasbob.com/Code/ScriptVault.aspx?script_id=80">http://www.lifeasbob.com/Code/ScriptVault.aspx?script_id=80</a> 
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=40a43d05-603c-40e4-9a31-6f3c369c2e1f" />
      </body>
      <title>Copy Jobs from one Server to Another</title>
      <guid isPermaLink="false">http://www.lifeasbob.com/PermaLink,guid,40a43d05-603c-40e4-9a31-6f3c369c2e1f.aspx</guid>
      <link>http://www.lifeasbob.com/2009/06/24/CopyJobsFromOneServerToAnother.aspx</link>
      <pubDate>Wed, 24 Jun 2009 15:43:24 GMT</pubDate>
      <description>&lt;p&gt;
This script copies jobs from one msdb database to another, useful for when SQL Server
is re-installed, and the DBA Forgot to script out the sql agent jobs; but you still
have the old msdb mdf and ldf.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
Simply attach the database as msdb_old.
&lt;/p&gt;
&lt;p&gt;
It is also possible to use this via a linked server and copy some sqlagent jobs from
one server to another; this script is specific to sql server 2005.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
One item I had to adjust is that some of the jobs appeared "greyed" out afterwards
and I had to open each job and adjust the target server to "local".&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
But it was still quicker than re-creating all the jobs.&amp;nbsp; (I was unable to restore
the previous version of the msdb database because it was at a lower service pack level
than what the new server was built at - had I been smart as the new server was built
there would have been a restore of the msdb database completed when the new server
was at the same level, but I missed that step and was then left with the task of recreating
all the jobs, argh).
&lt;/p&gt;
&lt;p&gt;
I'd be cautious using this script if there were a lot of reporting subscription jobs
(as there would have to be some synchronizations with the report database and website),
but in this particular case all the jobs were custom backups, tlogs, exports, imports
and other purely tsql and ssis related tasks.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.lifeasbob.com/Code/ScriptVault.aspx?script_id=80"&gt;http://www.lifeasbob.com/Code/ScriptVault.aspx?script_id=80&lt;/a&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=40a43d05-603c-40e4-9a31-6f3c369c2e1f" /&gt;</description>
      <comments>http://www.lifeasbob.com/CommentView,guid,40a43d05-603c-40e4-9a31-6f3c369c2e1f.aspx</comments>
      <category>SQL Server</category>
      <category>SQL Server / SQL Agent</category>
    </item>
    <item>
      <trackback:ping>http://www.lifeasbob.com/Trackback.aspx?guid=09081e3c-12a4-444b-85dc-d90ab7cca192</trackback:ping>
      <pingback:server>http://www.lifeasbob.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.lifeasbob.com/PermaLink,guid,09081e3c-12a4-444b-85dc-d90ab7cca192.aspx</pingback:target>
      <dc:creator>Bob Admin</dc:creator>
      <wfw:comment>http://www.lifeasbob.com/CommentView,guid,09081e3c-12a4-444b-85dc-d90ab7cca192.aspx</wfw:comment>
      <wfw:commentRss>http://www.lifeasbob.com/SyndicationService.asmx/GetEntryCommentsRss?guid=09081e3c-12a4-444b-85dc-d90ab7cca192</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Affinity mask keeping SQL Server Agent from starting.
</p>
        <img src="http://www.lifeasbob.com/content/binary/one_more_beer2.jpg" border="0" />
        <p>
Recently had a unique issue in one of our HP Polyserve clustered environments. 
One of the unique aspects of HP Polyserve is that you can cluster different types
of hardware.  This can reduce costs and risks (as a bug in firmware or hardware
on one machine is also most likely going to exist in the other node, especially if
they are the same make, model, and usually purchased together).
</p>
        <br />
        <p>
We had an affinity mask set on a 16 processor machine, the instance was intentionally
re-hosted to another server in the cluster, which was an 8 way machine.  The
instance did start, but SQL Agent would not.
</p>
        <br />
        <p>
The following error messages were found in the sql errorlog:
</p>
        <blockquote dir="ltr" style="MARGIN-RIGHT: 0px">
          <p>
            <font color="#ff0000">initconfig: Warning: affinity mask specified is not valid. Defaulting
to no affinity. Use sp_configure 'affinity mask' or 'affinity64 mask' to configure
the system to be compatible with the CPU mask on the system. You can also configure
the system based on the number of licensed CPUs.</font>
          </p>
          <br />
          <p>
            <font color="#ff0000">SQL Server blocked access to procedure 'dbo.sp_sqlagent_has_server_access'
of component 'Agent XPs' because this component is turned off as part of the security
configuration for this server. A system administrator can enable the use of 'Agent
XPs' by using sp_configure. For more information about enabling 'Agent XPs', see "Surface
Area Configuration" in SQL Server Books Online.</font>
          </p>
        </blockquote>
        <p>
A quick bit of research showed a similiar issue in a Microsoft Cluster, where the
one node did not have the correct permissions for the "lock pages in memory" setting,
causing the same result of SQL Agent not starting, you can see a great write up of
this in <a href="http://blogs.msdn.com/suhde/archive/2009/03/14/sql-server-agent-is-unable-to-failover-on-a-cluster.aspx">Suhas'
blog</a>.
</p>
        <br />
        <p>
Seems if the "start up" process for a SQL Server instance is interupted that the settings
changed from the defaults in sp_configure are not set and the process does not continue. 
From what I can determine this "start up" process is the settings contained in sp_configure,
if any of these fail along the way the process just stops or rolls them back and the
other settings like "Agent XPs" (required to start sql agent), will not occur.
</p>
        <br />
        <p>
I think this is a behavior that should not exist in SQL Server, why does an incorrect
affinity mask keep SQL Server from finishing running the other settings set by sp_configure
?  These options should be mutually exclusive and one failure should not preclude
others from running.
</p>
        <p>
I've had similar issues with how SQL Server starts up affecting SQL Agent, and it
does not appear to be a priority to fix, see my post on <a href="http://www.lifeasbob.com/2008/02/06/SQLAgentWillNotStartWhenAUserDatabaseIsInRecovery.aspx">SQL
Agent will not start when a user database is in recovery</a>. 
</p>
        <br />
        <p>
This was easy to fix, but required setting a correct affinity mask and stopping and
starting the service.  Generally we don't use an affinity mask on many instances. 
HP Polyserve provides pre and post start up scripts which we'll use to address the
issue in the future, though in extreme cases of failure no pre shutdown script will
be effective.  Plan your failover capacity carefully.<br /></p>
        <img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=09081e3c-12a4-444b-85dc-d90ab7cca192" />
      </body>
      <title>Some Days you need one of these...</title>
      <guid isPermaLink="false">http://www.lifeasbob.com/PermaLink,guid,09081e3c-12a4-444b-85dc-d90ab7cca192.aspx</guid>
      <link>http://www.lifeasbob.com/2009/05/20/SomeDaysYouNeedOneOfThese.aspx</link>
      <pubDate>Wed, 20 May 2009 20:26:52 GMT</pubDate>
      <description>&lt;p&gt;
Affinity mask keeping SQL Server Agent from starting.
&lt;/p&gt;
&lt;img src="http://www.lifeasbob.com/content/binary/one_more_beer2.jpg" border=0&gt; 
&lt;p&gt;
Recently had a unique issue in one of our HP Polyserve clustered environments.&amp;nbsp;
One of the unique aspects of HP Polyserve is that you can cluster different types
of hardware.&amp;nbsp; This can reduce costs and risks (as a bug in firmware or hardware
on one machine is also most likely going to exist in the other node, especially if
they are the same make, model, and usually purchased together).
&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;
We had an affinity mask set on a 16 processor machine, the instance was intentionally
re-hosted to another server in the cluster, which was an 8 way machine.&amp;nbsp; The
instance did start, but SQL Agent would not.
&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;
The following error messages were found in the sql errorlog:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
&lt;font color=#ff0000&gt;initconfig: Warning: affinity mask specified is not valid. Defaulting
to no affinity. Use sp_configure 'affinity mask' or 'affinity64 mask' to configure
the system to be compatible with the CPU mask on the system. You can also configure
the system based on the number of licensed CPUs.&lt;/font&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;
&lt;font color=#ff0000&gt;SQL Server blocked access to procedure 'dbo.sp_sqlagent_has_server_access'
of component 'Agent XPs' because this component is turned off as part of the security
configuration for this server. A system administrator can enable the use of 'Agent
XPs' by using sp_configure. For more information about enabling 'Agent XPs', see "Surface
Area Configuration" in SQL Server Books Online.&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
A quick bit of research showed a similiar issue in a Microsoft Cluster, where the
one node did not have the correct permissions for the "lock pages in memory" setting,
causing the same result of SQL Agent not starting, you can see a great write up of
this in &lt;a href="http://blogs.msdn.com/suhde/archive/2009/03/14/sql-server-agent-is-unable-to-failover-on-a-cluster.aspx"&gt;Suhas'
blog&lt;/a&gt;.
&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;
Seems if the "start up" process for a SQL Server instance is interupted that the settings
changed from the defaults in sp_configure are not set and the process does not continue.&amp;nbsp;
From what I can determine this "start up" process is the settings contained in sp_configure,
if any of these fail along the way the process just stops or rolls them back and the
other settings like "Agent XPs" (required to start sql agent), will not occur.
&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;
I think this is a behavior that should not exist in SQL Server, why does an incorrect
affinity mask keep SQL Server from finishing running the other settings set by sp_configure
?&amp;nbsp; These options should be mutually exclusive and one failure should not preclude
others from running.
&lt;/p&gt;
&lt;p&gt;
I've had similar issues with how SQL Server starts up affecting SQL Agent, and it
does not appear to be a priority to fix, see my post on &lt;a href="http://www.lifeasbob.com/2008/02/06/SQLAgentWillNotStartWhenAUserDatabaseIsInRecovery.aspx"&gt;SQL
Agent will not start when a user database is in recovery&lt;/a&gt;.&amp;nbsp;
&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;
This was easy to fix, but required setting a correct affinity mask and stopping and
starting the service.&amp;nbsp; Generally we don't use an affinity mask on many instances.&amp;nbsp;
HP Polyserve provides pre and post start up scripts which we'll use to address the
issue in the future, though in extreme cases of failure no pre shutdown script will
be effective.&amp;nbsp; Plan your failover capacity carefully.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=09081e3c-12a4-444b-85dc-d90ab7cca192" /&gt;</description>
      <comments>http://www.lifeasbob.com/CommentView,guid,09081e3c-12a4-444b-85dc-d90ab7cca192.aspx</comments>
      <category>Polyserve</category>
      <category>SQL Server</category>
      <category>SQL Server / SQL Agent</category>
    </item>
    <item>
      <trackback:ping>http://www.lifeasbob.com/Trackback.aspx?guid=29156669-0891-4709-b8db-20d8ec3a0e83</trackback:ping>
      <pingback:server>http://www.lifeasbob.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.lifeasbob.com/PermaLink,guid,29156669-0891-4709-b8db-20d8ec3a0e83.aspx</pingback:target>
      <dc:creator>Bob Admin</dc:creator>
      <wfw:comment>http://www.lifeasbob.com/CommentView,guid,29156669-0891-4709-b8db-20d8ec3a0e83.aspx</wfw:comment>
      <wfw:commentRss>http://www.lifeasbob.com/SyndicationService.asmx/GetEntryCommentsRss?guid=29156669-0891-4709-b8db-20d8ec3a0e83</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
SQL Agent job listing, jobs, steps and tsql / commands executed.
</p>
        <p>
Not really useful, but helpful when someone wants to see all the jobs and the steps
they are executing.
</p>
        <p>
Save as an excel file, or publish to rdl and push to a reporting site so they can
always see it themselves....
</p>
        <p>
select sj.name,sj.description,sjs.step_name,<br />
 sjs.subsystem,sjs.command,sjs.database_name,<br />
 sjs.output_file_name<br />
 from sysjobs sj<br />
 inner join sysjobsteps sjs on sj.job_id = sjs.job_id<br />
-- where sj.name like 'cy%'<br />
 order by sj.job_id,sjs.step_id
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=29156669-0891-4709-b8db-20d8ec3a0e83" />
      </body>
      <title>Job listing with steps and tsql</title>
      <guid isPermaLink="false">http://www.lifeasbob.com/PermaLink,guid,29156669-0891-4709-b8db-20d8ec3a0e83.aspx</guid>
      <link>http://www.lifeasbob.com/2008/10/22/JobListingWithStepsAndTsql.aspx</link>
      <pubDate>Wed, 22 Oct 2008 18:05:02 GMT</pubDate>
      <description>&lt;p&gt;
SQL Agent job listing, jobs, steps and tsql / commands executed.
&lt;/p&gt;
&lt;p&gt;
Not really useful, but helpful when someone wants to see all the jobs and the steps
they are executing.
&lt;/p&gt;
&lt;p&gt;
Save as an excel file, or publish to rdl and push to a reporting site so they can
always see it themselves....
&lt;/p&gt;
&lt;p&gt;
select sj.name,sj.description,sjs.step_name,&lt;br&gt;
&amp;nbsp;sjs.subsystem,sjs.command,sjs.database_name,&lt;br&gt;
&amp;nbsp;sjs.output_file_name&lt;br&gt;
&amp;nbsp;from sysjobs sj&lt;br&gt;
&amp;nbsp;inner join sysjobsteps sjs on sj.job_id = sjs.job_id&lt;br&gt;
--&amp;nbsp;where sj.name like 'cy%'&lt;br&gt;
&amp;nbsp;order by sj.job_id,sjs.step_id
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=29156669-0891-4709-b8db-20d8ec3a0e83" /&gt;</description>
      <comments>http://www.lifeasbob.com/CommentView,guid,29156669-0891-4709-b8db-20d8ec3a0e83.aspx</comments>
      <category>SQL Server / SQL Agent</category>
    </item>
    <item>
      <trackback:ping>http://www.lifeasbob.com/Trackback.aspx?guid=b957c95c-92db-4d0a-a485-700dd6a3a731</trackback:ping>
      <pingback:server>http://www.lifeasbob.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.lifeasbob.com/PermaLink,guid,b957c95c-92db-4d0a-a485-700dd6a3a731.aspx</pingback:target>
      <dc:creator>Bob Admin</dc:creator>
      <wfw:comment>http://www.lifeasbob.com/CommentView,guid,b957c95c-92db-4d0a-a485-700dd6a3a731.aspx</wfw:comment>
      <wfw:commentRss>http://www.lifeasbob.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b957c95c-92db-4d0a-a485-700dd6a3a731</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Began receiving alerts on a job failing.  The job was "suspended".  The
error in the history event log is:
</p>
        <p>
Unable to start execution of step 2 (reason: The ActiveScripting subsystem failed
to load [see the SQLAGENT.OUT file for details]; The job has been suspended). 
The step failed.
</p>
        <img src="http://www.lifeasbob.com/content/binary/sqlagent_error.JPG" border="0" />
        <p>
A quick review of the server shows MSDE was installed on the machine, somehow this
causes an error in the registry.
</p>
        <p>
Review the below registry entry and ensure there is an "s" at the end.  According
to Microsoft this happens sometimes with MSDE installations and upgrades.  You
can see the picture of mine, that it was missing
</p>
        <p>
          <font color="#191970">[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\80\Tools\ClientSetup]<br />
"SQLPath"="C:\Program Files\Microsoft SQL Server\80\Tools"<br /></font>
        </p>
        <p>
          <img src="http://www.lifeasbob.com/content/binary/sqlagent_clienttools.JPG" border="0" />
          <br />
I added the "s" to the end.  Started and stop the instance (i did both services
because I could, but may only need to have the agent service restarted.)
</p>
        <p>
Everything is working fine now.
</p>
        <p>
This was on a sql server 2000 installation.
</p>
        <img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=b957c95c-92db-4d0a-a485-700dd6a3a731" />
      </body>
      <title>SQL Agent - ActiveScripting subsystem failed to load</title>
      <guid isPermaLink="false">http://www.lifeasbob.com/PermaLink,guid,b957c95c-92db-4d0a-a485-700dd6a3a731.aspx</guid>
      <link>http://www.lifeasbob.com/2008/03/31/SQLAgentActiveScriptingSubsystemFailedToLoad.aspx</link>
      <pubDate>Mon, 31 Mar 2008 16:58:59 GMT</pubDate>
      <description>&lt;p&gt;
Began receiving alerts on a job failing.&amp;nbsp; The job was "suspended".&amp;nbsp; The
error in the history event log is:
&lt;/p&gt;
&lt;p&gt;
Unable to start execution of step 2 (reason: The ActiveScripting subsystem failed
to load [see the SQLAGENT.OUT file for details]; The job has been suspended).&amp;nbsp;
The step failed.
&lt;/p&gt;
&lt;img src="http://www.lifeasbob.com/content/binary/sqlagent_error.JPG" border=0&gt; 
&lt;p&gt;
A quick review of the server shows MSDE was installed on the machine, somehow this
causes an error in the registry.
&lt;/p&gt;
&lt;p&gt;
Review the below registry entry and ensure there is an "s" at the end.&amp;nbsp; According
to Microsoft this happens sometimes with MSDE installations and upgrades.&amp;nbsp; You
can see the picture of mine, that it was missing
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#191970&gt;[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\80\Tools\ClientSetup]&lt;br&gt;
"SQLPath"="C:\Program Files\Microsoft SQL Server\80\Tools"&lt;br&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.lifeasbob.com/content/binary/sqlagent_clienttools.JPG" border=0&gt; 
&lt;br&gt;
I added the "s" to the end.&amp;nbsp; Started and stop the instance (i did both services
because I could, but may only need to have the agent service restarted.)
&lt;/p&gt;
&lt;p&gt;
Everything is working fine now.
&lt;/p&gt;
&lt;p&gt;
This was on a sql server 2000 installation.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=b957c95c-92db-4d0a-a485-700dd6a3a731" /&gt;</description>
      <comments>http://www.lifeasbob.com/CommentView,guid,b957c95c-92db-4d0a-a485-700dd6a3a731.aspx</comments>
      <category>SQL Server</category>
      <category>SQL Server / SQL Agent</category>
    </item>
    <item>
      <trackback:ping>http://www.lifeasbob.com/Trackback.aspx?guid=ba9765f1-0d06-4638-b78e-fc50918aaa55</trackback:ping>
      <pingback:server>http://www.lifeasbob.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.lifeasbob.com/PermaLink,guid,ba9765f1-0d06-4638-b78e-fc50918aaa55.aspx</pingback:target>
      <dc:creator>Bob Admin</dc:creator>
      <wfw:comment>http://www.lifeasbob.com/CommentView,guid,ba9765f1-0d06-4638-b78e-fc50918aaa55.aspx</wfw:comment>
      <wfw:commentRss>http://www.lifeasbob.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ba9765f1-0d06-4638-b78e-fc50918aaa55</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
SQL Server does a great job of logging, but anyone who administers a sql server should
adjust some of the "out of the box" defaults for an instance, and create some custom
jobs in sql agent to control output of jobs.
</p>
        <p>
By default sql server logs information to ErrorLog.  Depending on your version
of SQL Server (7.0, 2000 or 2005) and a default or named instance it is located along
a path similiar to the following:
</p>
        <p>
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG 
</p>
        <p>
C:\Program Files\Microsoft SQL Server\MSSQL\MSSQL${Instance}\LOG
</p>
        <p>
The ErrorLog is a great source of monitoring and should be scraped and reviewed regularly,
but by default there are only 6 log files kept on disk, and a new log file is started
evertime an instance is started or "cycled".  This is not adequate, an administrator
applying a patch to a server seems to require 3 reboots and you don't want to
find out that information needed in a log file was lost due to not having enough of
them.  We run this to 30 log files kept on disk and cycle the error log daily
at 12am via a sql agent job.  This is very easy and can be adjusted via gui in
SQL Enterprise Manager or in SQL Server Managemetn Studio by right clicking on
the SQL Server Logs and selecting "Configure", which will bring up the dialog below,
adjust to any number, but definetly 6 is not enough !
</p>
        <p>
          <img src="http://www.lifeasbob.com/content/binary/sql%20server%20Configure%20Error%20Logs.JPG" border="0" />
        </p>
        <p>
It can also be adjusted via TSQL, but requires xp_instance_regwrite and is highly
dependent that you know the structure of the registry for your particular instance
and version of sql server, this is one case where using the GUI is the best option,
but it is possible to do via tsql:
</p>
        <p>
EXECUTE master.dbo.xp_instance_regwrite<br />
N'HKEY_LOCAL_MACHINE'<br />
,N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer' --****!!!! VERIFY 
<br />
,N'NumErrorlogs'<br />
,REG_DWORD<br />
,30 -- number of errorlogs you want to keep<br />
GO 
<br /></p>
        <p>
After configuring the instance to retain 30 errorLogs, now you need to implement a
sql agent job to cycle the error logs daily at 12am.  This is very easily implemented
with a job scheduled to run:<br />
Exec sp_cycle_ErrorLog.
</p>
        <p>
Now onto the good one, SQL Server Agent and the output from jobs.
</p>
        <p>
After managing SQL Server Agent jobs for many years it is apparent that the default
options for logging of jobs, Overwrite and Append, is not adequate.  Most of
the time we default the logs to append, but overtime and depending on the amount of
output these log files, they can become very large, difficult to open, difficult
to read and waste valuable time when you have to trouble shoot a job.  This applies
to sql server 7.0, 2000 and 2005 and is highly dependent on having all your jobs and
logging go to the same directory (if they are currently "scattered" you can correct
them manually or through tsql in the sysjobsteps table, with a mass update).
</p>
        <p>
We have developed a jobs that we host on every sql agent instance, Log Archive. 
It is a two step job consisting of TSQL and Active X Scripting.  One step moves
all the log files to a sub-directory for that day.  The 2nd step of the job removes
the sub-directories older than x days (we default to 30).  This makes it very
easy to find a log file for a particular day, based on the naming convention of the
sub-directories.  This job runs daily at 11:58pm.  Example below:
</p>
        <p>
          <img src="http://www.lifeasbob.com/content/binary/sql_agent_log_archive_job.JPG" border="0" />
        </p>
        <p>
The code for the two steps is attached, they will require editing for your specific
directory structure and number of sub-directories to retain.
</p>
        <p>
          <a href="http://www.lifeasbob.com/content/binary/Archive_Daily_Logs.txt">Archive_Daily_Logs.txt
(.7 KB)</a> 
</p>
        <p>
          <a href="http://www.lifeasbob.com/content/binary/VBScript_Delete_Old_Dirs.txt">VBScript_Delete_Old_Dirs.txt
(.52 KB)</a> 
</p>
        <p>
This creates a great directory tree, easy to maintain, easy to troubleshoot:
</p>
        <p>
          <img src="http://www.lifeasbob.com/content/binary/joblogs.JPG" border="0" />
        </p>
        <img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=ba9765f1-0d06-4638-b78e-fc50918aaa55" />
      </body>
      <title>SQL Server Log Management</title>
      <guid isPermaLink="false">http://www.lifeasbob.com/PermaLink,guid,ba9765f1-0d06-4638-b78e-fc50918aaa55.aspx</guid>
      <link>http://www.lifeasbob.com/2008/02/26/SQLServerLogManagement.aspx</link>
      <pubDate>Tue, 26 Feb 2008 19:07:45 GMT</pubDate>
      <description>&lt;p&gt;
SQL Server does a great job of logging, but anyone who administers a sql server should
adjust some of the "out of the box" defaults for an instance, and create some custom
jobs in sql agent to control output of jobs.
&lt;/p&gt;
&lt;p&gt;
By default sql server logs information to ErrorLog.&amp;nbsp; Depending on your version
of SQL Server (7.0, 2000 or 2005) and a default or named instance it is located along
a path similiar to the following:
&lt;/p&gt;
&lt;p&gt;
C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG 
&lt;/p&gt;
&lt;p&gt;
C:\Program Files\Microsoft SQL Server\MSSQL\MSSQL${Instance}\LOG
&lt;/p&gt;
&lt;p&gt;
The ErrorLog is a great source of monitoring and should be scraped and reviewed regularly,
but by default there are only 6 log files kept on disk, and a new log file is started
evertime an instance is&amp;nbsp;started or "cycled".&amp;nbsp; This is not adequate, an administrator
applying a patch to a server&amp;nbsp;seems to require 3 reboots and you don't want to
find out that information needed in a log file was lost due to not having enough of
them.&amp;nbsp; We run this to 30 log files kept on disk and cycle the error log daily
at 12am via a sql agent job.&amp;nbsp; This is very easy and can be adjusted via gui in
SQL Enterprise Manager or in SQL Server Managemetn Studio&amp;nbsp;by right clicking on
the SQL Server Logs and selecting "Configure", which will bring up the dialog below,
adjust to any number, but definetly 6 is not enough !
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.lifeasbob.com/content/binary/sql%20server%20Configure%20Error%20Logs.JPG" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
It can also be adjusted via TSQL, but requires xp_instance_regwrite and is highly
dependent that you know the structure of the registry for your particular instance
and version of sql server, this is one case where using the GUI is the best option,
but it is possible to do via tsql:
&lt;/p&gt;
&lt;p&gt;
EXECUTE master.dbo.xp_instance_regwrite&lt;br&gt;
N'HKEY_LOCAL_MACHINE'&lt;br&gt;
,N'SOFTWARE\Microsoft\MSSQLServer\MSSQLServer' --****!!!! VERIFY 
&lt;br&gt;
,N'NumErrorlogs'&lt;br&gt;
,REG_DWORD&lt;br&gt;
,30 -- number of errorlogs you want to keep&lt;br&gt;
GO 
&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
After configuring the instance to retain 30 errorLogs, now you need to implement a
sql agent job to cycle the error logs daily at 12am.&amp;nbsp; This is very easily implemented
with a job scheduled to run:&lt;br&gt;
Exec sp_cycle_ErrorLog.
&lt;/p&gt;
&lt;p&gt;
Now onto the good one, SQL Server Agent and the output from jobs.
&lt;/p&gt;
&lt;p&gt;
After managing SQL Server Agent jobs for many years it is apparent that the default
options for logging of jobs, Overwrite and Append, is not adequate.&amp;nbsp; Most of
the time we default the logs to append, but overtime and depending on the amount of
output these log files, they can&amp;nbsp;become very large, difficult to open, difficult
to read and waste valuable time when you have to trouble shoot a job.&amp;nbsp; This applies
to sql server 7.0, 2000 and 2005 and is highly dependent on having all your jobs and
logging go to the same directory (if they are currently "scattered" you can correct
them manually or through tsql in the sysjobsteps table, with a mass update).
&lt;/p&gt;
&lt;p&gt;
We have developed a jobs that we host on every sql agent instance, Log Archive.&amp;nbsp;
It is a two step job consisting of TSQL and Active X Scripting.&amp;nbsp; One step moves
all the log files to a sub-directory for that day.&amp;nbsp; The 2nd step of the job removes
the sub-directories older than x days (we default to 30).&amp;nbsp; This makes it very
easy to find a log file for a particular day, based on the naming convention of the
sub-directories.&amp;nbsp; This job runs daily at 11:58pm.&amp;nbsp; Example below:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.lifeasbob.com/content/binary/sql_agent_log_archive_job.JPG" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
The code for the two steps is attached, they will require editing for your specific
directory structure and number of sub-directories to retain.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.lifeasbob.com/content/binary/Archive_Daily_Logs.txt"&gt;Archive_Daily_Logs.txt
(.7 KB)&lt;/a&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.lifeasbob.com/content/binary/VBScript_Delete_Old_Dirs.txt"&gt;VBScript_Delete_Old_Dirs.txt
(.52 KB)&lt;/a&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This creates a great directory tree, easy to maintain, easy to troubleshoot:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.lifeasbob.com/content/binary/joblogs.JPG" border=0&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=ba9765f1-0d06-4638-b78e-fc50918aaa55" /&gt;</description>
      <comments>http://www.lifeasbob.com/CommentView,guid,ba9765f1-0d06-4638-b78e-fc50918aaa55.aspx</comments>
      <category>SQL Server</category>
      <category>SQL Server / SQL Agent</category>
    </item>
    <item>
      <trackback:ping>http://www.lifeasbob.com/Trackback.aspx?guid=948d3f74-5793-4a41-9daf-450b805e779e</trackback:ping>
      <pingback:server>http://www.lifeasbob.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.lifeasbob.com/PermaLink,guid,948d3f74-5793-4a41-9daf-450b805e779e.aspx</pingback:target>
      <dc:creator>Bob Admin</dc:creator>
      <wfw:comment>http://www.lifeasbob.com/CommentView,guid,948d3f74-5793-4a41-9daf-450b805e779e.aspx</wfw:comment>
      <wfw:commentRss>http://www.lifeasbob.com/SyndicationService.asmx/GetEntryCommentsRss?guid=948d3f74-5793-4a41-9daf-450b805e779e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Polyserve clusters SQL Server instances, and can then rehost them or fail them over
to other servers.
</p>
        <p>
One of the issues we've run into with Polyserve is when we move a sql server instance
from one machine to another where the binaries change location from mssql.a to mssql.b. 
</p>
        <p>
SQL Agent (SQLAgent.exe, SQLAgent), utilizes a system table in msdb for starting and
executing jobs, called syssubsystems;
</p>
        <p>
Execute: select * from msdb.dbo.syssubsystems and you will see each sub-system of
sql agent and the path to the binaries, if a sql server instance is moved through
some technology like Polyserve or through manually moving a msdb database from one
server to another and the path to the binaries change, the system tables will need
to be updated to the new path.
</p>
        <p>
We've experienced this on Polyserve and when we moved a sql server instance from one
server to another and copied msdb.
</p>
        <p>
very easy to fix, but frustrating, below is  a snippet which can be run to correct
the issue:
</p>
        <font color="#008000" size="2">
          <p>
--Get SQLBinRoot 
</p>
        </font>
        <font color="#0000ff" size="2">
          <p>
declare
</p>
        </font>
        <font color="#000000" size="2"> @ret </font>
        <font color="#0000ff" size="2">sysname</font>
        <font size="2">
          <font color="#000000">
          </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
exec
</p>
        </font>
        <font color="#000000" size="2"> master</font>
        <font color="#808080" size="2">..</font>
        <font color="#000000" size="2">xp_instance_regread </font>
        <font color="#ff0000" size="2">'HKEY_LOCAL_MACHINE'</font>
        <font color="#808080" size="2">,</font>
        <font color="#ff0000" size="2">'Software\Microsoft\MSSQLServer\Setup'</font>
        <font color="#808080" size="2">,</font>
        <font color="#ff0000" size="2">'SQLBinRoot'</font>
        <font color="#808080" size="2">,</font>
        <font color="#000000" size="2">@ret </font>
        <font color="#0000ff" size="2">OUTPUT</font>
        <font size="2">
          <font color="#000000">
          </font>
        </font>
        <font color="#008000" size="2">
          <p>
--Update subsystem_dll to current SQLBinRoot 
</p>
        </font>
        <font color="#0000ff" size="2">
          <p>
update
</p>
        </font>
        <font size="2">
          <font color="#000000"> sub </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
set
</p>
        </font>
        <font color="#000000" size="2"> subsystem_dll</font>
        <font color="#808080" size="2">=</font>
        <font color="#000000" size="2">@ret</font>
        <font color="#808080" size="2">+</font>
        <font color="#ff00ff" size="2">substring</font>
        <font color="#808080" size="2">(</font>
        <font color="#000000" size="2">subsystem_dll</font>
        <font color="#808080" size="2">,</font>
        <font color="#ff00ff" size="2">charindex</font>
        <font color="#808080" size="2">(</font>
        <font color="#ff0000" size="2">'\binn\'</font>
        <font color="#808080" size="2">,</font>
        <font color="#000000" size="2">subsystem_dll</font>
        <font color="#808080" size="2">)+</font>
        <font color="#000000" size="2">5</font>
        <font color="#808080" size="2">,</font>
        <font color="#000000" size="2">30</font>
        <font color="#808080" size="2">)</font>
        <font size="2">
          <font color="#000000">
          </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
from
</p>
        </font>
        <font color="#000000" size="2"> msdb</font>
        <font color="#808080" size="2">..</font>
        <font size="2">
          <font color="#000000">syssubsystems
sub </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
where
</p>
        </font>
        <font color="#000000" size="2">
        </font>
        <font color="#ff00ff" size="2">charindex</font>
        <font color="#808080" size="2">(</font>
        <font color="#ff0000" size="2">'\binn\'</font>
        <font color="#808080" size="2">,</font>
        <font color="#000000" size="2">subsystem_dll</font>
        <font color="#808080" size="2">)&gt;</font>
        <font size="2">
          <font color="#000000">0 </font>
        </font>
        <font color="#008000" size="2">
          <p>
--Stop Sqlagent service if running 
</p>
          <p>
--MxDB should restart it automatically 
</p>
        </font>
        <font color="#0000ff" size="2">
          <p>
declare
</p>
        </font>
        <font color="#000000" size="2"> @service </font>
        <font color="#0000ff" size="2">sysname</font>
        <font size="2">
          <font color="#000000">
          </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
select
</p>
        </font>
        <font color="#000000" size="2"> @service </font>
        <font color="#808080" size="2">=</font>
        <font color="#000000" size="2">
        </font>
        <font color="#0000ff" size="2">case</font>
        <font color="#000000" size="2">
        </font>
        <font color="#0000ff" size="2">when</font>
        <font color="#000000" size="2">
        </font>
        <font color="#ff00ff" size="2">charindex</font>
        <font color="#808080" size="2">(</font>
        <font color="#ff0000" size="2">'\'</font>
        <font color="#808080" size="2">,</font>
        <font color="#ff00ff" size="2">@@servername</font>
        <font color="#808080" size="2">)&gt;</font>
        <font size="2">
          <font color="#000000">0 </font>
          <p>
          </p>
        </font>
        <font color="#0000ff" size="2">then</font>
        <font size="2"> N</font>
        <font color="#ff0000" size="2">'SQLAgent$'</font>
        <font color="#808080" size="2">+</font>
        <font color="#ff00ff" size="2">@@servicename</font>
        <font size="2">
          <p>
          </p>
        </font>
        <font color="#0000ff" size="2">else</font>
        <font size="2"> N</font>
        <font color="#ff0000" size="2">'SQLSERVERAGENT'</font>
        <font size="2">
        </font>
        <font color="#0000ff" size="2">end</font>
        <font size="2">
        </font>
        <font color="#0000ff" size="2">
          <p>
create
</p>
        </font>
        <font color="#000000" size="2">
        </font>
        <font color="#0000ff" size="2">table</font>
        <font color="#000000" size="2"> #stat</font>
        <font color="#808080" size="2">(</font>
        <font color="#0000ff" size="2">status</font>
        <font color="#000000" size="2">
        </font>
        <font color="#0000ff" size="2">sysname</font>
        <font color="#808080" size="2">)</font>
        <font size="2">
          <font color="#000000">
          </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
insert
</p>
        </font>
        <font size="2">
          <font color="#000000"> #stat </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
exec
</p>
        </font>
        <font color="#000000" size="2"> master</font>
        <font color="#808080" size="2">..</font>
        <font color="#000000" size="2">xp_servicecontrol
N</font>
        <font color="#ff0000" size="2">'QUERYSTATE'</font>
        <font color="#808080" size="2">,</font>
        <font size="2">
          <font color="#000000"> @service </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
if
</p>
        </font>
        <font color="#000000" size="2">
        </font>
        <font color="#808080" size="2">exists(</font>
        <font color="#0000ff" size="2">select</font>
        <font color="#000000" size="2">
        </font>
        <font color="#808080" size="2">*</font>
        <font color="#000000" size="2">
        </font>
        <font color="#0000ff" size="2">from</font>
        <font color="#000000" size="2"> #stat </font>
        <font color="#0000ff" size="2">where</font>
        <font color="#000000" size="2">
        </font>
        <font color="#0000ff" size="2">status</font>
        <font color="#808080" size="2">=</font>
        <font color="#ff0000" size="2">'Running.'</font>
        <font color="#808080" size="2">)</font>
        <font size="2">
          <font color="#000000">
          </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
begin
</p>
        </font>
        <font size="2">
          <font color="#000000">
          </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
exec
</p>
        </font>
        <font color="#000000" size="2"> master</font>
        <font color="#808080" size="2">..</font>
        <font color="#000000" size="2">xp_servicecontrol
N</font>
        <font color="#ff0000" size="2">'STOP'</font>
        <font color="#808080" size="2">,</font>
        <font size="2">
          <font color="#000000"> @service </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
end
</p>
        </font>
        <font size="2">
          <font color="#000000">
          </font>
        </font>
        <font color="#008000" size="2">
          <p>
--Clean up tmp table 
</p>
        </font>
        <font color="#0000ff" size="2">
          <p>
if
</p>
        </font>
        <font color="#000000" size="2">
        </font>
        <font color="#ff00ff" size="2">object_id</font>
        <font color="#808080" size="2">(</font>
        <font color="#ff0000" size="2">'tempdb..#stat'</font>
        <font color="#808080" size="2">)</font>
        <font color="#000000" size="2">
        </font>
        <font color="#808080" size="2">is</font>
        <font color="#000000" size="2">
        </font>
        <font color="#808080" size="2">not</font>
        <font color="#000000" size="2">
        </font>
        <font color="#808080" size="2">null</font>
        <font size="2">
          <font color="#000000">
          </font>
        </font>
        <font color="#0000ff" size="2">
          <p>
drop
</p>
        </font>
        <font color="#000000" size="2">
        </font>
        <font color="#0000ff" size="2">table</font>
        <font size="2">
          <font color="#000000"> #stat</font>
        </font>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=948d3f74-5793-4a41-9daf-450b805e779e" />
      </body>
      <title>SQL Agent - MSSQL.4 vs MSSQL.1, - \'ActiveScripting\' could not be loaded</title>
      <guid isPermaLink="false">http://www.lifeasbob.com/PermaLink,guid,948d3f74-5793-4a41-9daf-450b805e779e.aspx</guid>
      <link>http://www.lifeasbob.com/2008/02/06/SQLAgentMSSQL4VsMSSQL1ActiveScriptingCouldNotBeLoaded.aspx</link>
      <pubDate>Wed, 06 Feb 2008 15:49:41 GMT</pubDate>
      <description>&lt;p&gt;
Polyserve clusters SQL Server instances, and can then rehost them or fail them over
to other servers.
&lt;/p&gt;
&lt;p&gt;
One of the issues we've run into with Polyserve is when we move a sql server instance
from one machine to another where the binaries change location from mssql.a to mssql.b. 
&lt;/p&gt;
&lt;p&gt;
SQL Agent (SQLAgent.exe, SQLAgent), utilizes a system table in msdb for starting and
executing jobs, called syssubsystems;
&lt;/p&gt;
&lt;p&gt;
Execute: select * from msdb.dbo.syssubsystems and you will see each sub-system of
sql agent and the path to the binaries, if a sql server instance is moved through
some technology like Polyserve or through manually moving a msdb database from one
server to another and the path to the binaries change, the system tables will need
to be updated to the new path.
&lt;/p&gt;
&lt;p&gt;
We've experienced this on Polyserve and when we moved a sql server instance from one
server to another and copied msdb.
&lt;/p&gt;
&lt;p&gt;
very easy to fix, but frustrating, below is&amp;nbsp; a snippet which can be run to correct
the issue:
&lt;/p&gt;
&lt;font color=#008000 size=2&gt; 
&lt;p&gt;
--Get SQLBinRoot 
&lt;/p&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
declare
&lt;/font&gt;&lt;font color=#000000 size=2&gt; @ret &lt;/font&gt;&lt;font color=#0000ff size=2&gt;sysname&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
exec
&lt;/font&gt;&lt;font color=#000000 size=2&gt; master&lt;/font&gt;&lt;font color=#808080 size=2&gt;..&lt;/font&gt;&lt;font color=#000000 size=2&gt;xp_instance_regread &lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'HKEY_LOCAL_MACHINE'&lt;/font&gt;&lt;font color=#808080 size=2&gt;,&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'Software\Microsoft\MSSQLServer\Setup'&lt;/font&gt;&lt;font color=#808080 size=2&gt;,&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'SQLBinRoot'&lt;/font&gt;&lt;font color=#808080 size=2&gt;,&lt;/font&gt;&lt;font color=#000000 size=2&gt;@ret &lt;/font&gt;&lt;font color=#0000ff size=2&gt;OUTPUT&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#008000 size=2&gt; 
&lt;p&gt;
--Update subsystem_dll to current SQLBinRoot 
&lt;/p&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
update
&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; sub &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
set
&lt;/font&gt;&lt;font color=#000000 size=2&gt; subsystem_dll&lt;/font&gt;&lt;font color=#808080 size=2&gt;=&lt;/font&gt;&lt;font color=#000000 size=2&gt;@ret&lt;/font&gt;&lt;font color=#808080 size=2&gt;+&lt;/font&gt;&lt;font color=#ff00ff size=2&gt;substring&lt;/font&gt;&lt;font color=#808080 size=2&gt;(&lt;/font&gt;&lt;font color=#000000 size=2&gt;subsystem_dll&lt;/font&gt;&lt;font color=#808080 size=2&gt;,&lt;/font&gt;&lt;font color=#ff00ff size=2&gt;charindex&lt;/font&gt;&lt;font color=#808080 size=2&gt;(&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'\binn\'&lt;/font&gt;&lt;font color=#808080 size=2&gt;,&lt;/font&gt;&lt;font color=#000000 size=2&gt;subsystem_dll&lt;/font&gt;&lt;font color=#808080 size=2&gt;)+&lt;/font&gt;&lt;font color=#000000 size=2&gt;5&lt;/font&gt;&lt;font color=#808080 size=2&gt;,&lt;/font&gt;&lt;font color=#000000 size=2&gt;30&lt;/font&gt;&lt;font color=#808080 size=2&gt;)&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
from
&lt;/font&gt;&lt;font color=#000000 size=2&gt; msdb&lt;/font&gt;&lt;font color=#808080 size=2&gt;..&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt;syssubsystems
sub &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
where
&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#ff00ff size=2&gt;charindex&lt;/font&gt;&lt;font color=#808080 size=2&gt;(&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'\binn\'&lt;/font&gt;&lt;font color=#808080 size=2&gt;,&lt;/font&gt;&lt;font color=#000000 size=2&gt;subsystem_dll&lt;/font&gt;&lt;font color=#808080 size=2&gt;)&amp;gt;&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt;0 &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#008000 size=2&gt; 
&lt;p&gt;
--Stop Sqlagent service if running 
&lt;/p&gt;
&lt;p&gt;
--MxDB should restart it automatically 
&lt;/p&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
declare
&lt;/font&gt;&lt;font color=#000000 size=2&gt; @service &lt;/font&gt;&lt;font color=#0000ff size=2&gt;sysname&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
select
&lt;/font&gt;&lt;font color=#000000 size=2&gt; @service &lt;/font&gt;&lt;font color=#808080 size=2&gt;=&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#0000ff size=2&gt;case&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#0000ff size=2&gt;when&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#ff00ff size=2&gt;charindex&lt;/font&gt;&lt;font color=#808080 size=2&gt;(&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'\'&lt;/font&gt;&lt;font color=#808080 size=2&gt;,&lt;/font&gt;&lt;font color=#ff00ff size=2&gt;@@servername&lt;/font&gt;&lt;font color=#808080 size=2&gt;)&amp;gt;&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt;0 &lt;/font&gt;&gt;
&lt;p&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt;then&lt;/font&gt;&lt;font size=2&gt; N&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'SQLAgent$'&lt;/font&gt;&lt;font color=#808080 size=2&gt;+&lt;/font&gt;&lt;font color=#ff00ff size=2&gt;@@servicename&lt;/font&gt;&lt;font size=2&gt; &gt;
&lt;p&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt;else&lt;/font&gt;&lt;font size=2&gt; N&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'SQLSERVERAGENT'&lt;/font&gt;&lt;font size=2&gt; &lt;/font&gt;&lt;font color=#0000ff size=2&gt;end&lt;/font&gt;&lt;font size=2&gt; &gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
create
&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#0000ff size=2&gt;table&lt;/font&gt;&lt;font color=#000000 size=2&gt; #stat&lt;/font&gt;&lt;font color=#808080 size=2&gt;(&lt;/font&gt;&lt;font color=#0000ff size=2&gt;status&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#0000ff size=2&gt;sysname&lt;/font&gt;&lt;font color=#808080 size=2&gt;)&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
insert
&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; #stat &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
exec
&lt;/font&gt;&lt;font color=#000000 size=2&gt; master&lt;/font&gt;&lt;font color=#808080 size=2&gt;..&lt;/font&gt;&lt;font color=#000000 size=2&gt;xp_servicecontrol
N&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'QUERYSTATE'&lt;/font&gt;&lt;font color=#808080 size=2&gt;,&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; @service &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
if
&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#808080 size=2&gt;exists(&lt;/font&gt;&lt;font color=#0000ff size=2&gt;select&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#808080 size=2&gt;*&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#0000ff size=2&gt;from&lt;/font&gt;&lt;font color=#000000 size=2&gt; #stat &lt;/font&gt;&lt;font color=#0000ff size=2&gt;where&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#0000ff size=2&gt;status&lt;/font&gt;&lt;font color=#808080 size=2&gt;=&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'Running.'&lt;/font&gt;&lt;font color=#808080 size=2&gt;)&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
begin
&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
exec
&lt;/font&gt;&lt;font color=#000000 size=2&gt; master&lt;/font&gt;&lt;font color=#808080 size=2&gt;..&lt;/font&gt;&lt;font color=#000000 size=2&gt;xp_servicecontrol
N&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'STOP'&lt;/font&gt;&lt;font color=#808080 size=2&gt;,&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; @service &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
end
&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#008000 size=2&gt; 
&lt;p&gt;
--Clean up tmp table 
&lt;/p&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
if
&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#ff00ff size=2&gt;object_id&lt;/font&gt;&lt;font color=#808080 size=2&gt;(&lt;/font&gt;&lt;font color=#ff0000 size=2&gt;'tempdb..#stat'&lt;/font&gt;&lt;font color=#808080 size=2&gt;)&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#808080 size=2&gt;is&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#808080 size=2&gt;not&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#808080 size=2&gt;null&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; &lt;/font&gt;&gt;
&lt;/font&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
drop
&lt;/font&gt;&lt;font color=#000000 size=2&gt; &lt;/font&gt;&lt;font color=#0000ff size=2&gt;table&lt;/font&gt;&lt;font size=2&gt;&lt;font color=#000000&gt; #stat&lt;/font&gt;&gt;
&lt;/font&gt; 
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=948d3f74-5793-4a41-9daf-450b805e779e" /&gt;</description>
      <comments>http://www.lifeasbob.com/CommentView,guid,948d3f74-5793-4a41-9daf-450b805e779e.aspx</comments>
      <category>Polyserve</category>
      <category>SQL Server / SQL Agent</category>
    </item>
    <item>
      <trackback:ping>http://www.lifeasbob.com/Trackback.aspx?guid=c7cc343d-880d-4353-9547-25f66f775a68</trackback:ping>
      <pingback:server>http://www.lifeasbob.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.lifeasbob.com/PermaLink,guid,c7cc343d-880d-4353-9547-25f66f775a68.aspx</pingback:target>
      <dc:creator>Bob Admin</dc:creator>
      <wfw:comment>http://www.lifeasbob.com/CommentView,guid,c7cc343d-880d-4353-9547-25f66f775a68.aspx</wfw:comment>
      <wfw:commentRss>http://www.lifeasbob.com/SyndicationService.asmx/GetEntryCommentsRss?guid=c7cc343d-880d-4353-9547-25f66f775a68</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <title>SQL Agent will not start when a user database is in recovery !</title>
      <guid isPermaLink="false">http://www.lifeasbob.com/PermaLink,guid,c7cc343d-880d-4353-9547-25f66f775a68.aspx</guid>
      <link>http://www.lifeasbob.com/2008/02/06/SQLAgentWillNotStartWhenAUserDatabaseIsInRecovery.aspx</link>
      <pubDate>Wed, 06 Feb 2008 15:42:45 GMT</pubDate>
      <description>&lt;p&gt;
This is crap, SQLAgent not starting because a user database is in recovery mode, after
restarting sql server.&amp;nbsp; Usually recovery&amp;nbsp;/ checkpointing of user databases
on start-up is really quick, but if one runs into an issue it can take a long long
time, this particular user database has been&amp;nbsp;recovering for 4+ hours.&amp;nbsp; Now
I have issues with&amp;nbsp;maintenance jobs and reporting services jobs not running because
sql agent&amp;nbsp;will not start.
&lt;/p&gt;
&lt;p&gt;
I can understand if msdb or some other system database is in recovery or suspect,
but not a damn user database !
&lt;/p&gt;
&lt;p&gt;
SQL Server Error Log:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
&lt;font color=#ff0000&gt;2008-02-06 09:38:44.07 spid10s&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Recovery
of database 'ClientAssistant_CY' (20) is 27% complete (approximately 38597 seconds
remain). Phase 3 of 3. This is an informational message only. No user action is required.&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
READ THAT, 38000+ seconds, over 10 HOURS, we can't wait that long !&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
SQL Agent Error Log:
&lt;/p&gt;
&lt;blockquote dir=ltr style="MARGIN-RIGHT: 0px"&gt; 
&lt;p&gt;
&lt;font color=#ff0000&gt;2008-02-06 08:44:55 - ? [393] Waiting for SQL Server to recover
databases...&lt;br&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
This is unreal, i'm going to have to de-attach / interrupt the recovery process; i
think, but to be sure i placed a support call to Microsoft.&lt;br&gt;
&lt;/p&gt;
&lt;p&gt;
According to Microsoft, this is a new feature of SQL Server 2005.&amp;nbsp; If SQL Server
Agent starts and not all the user databases on-line / recovered than sql server agent
stays in a starting mode and no jobs run.
&lt;/p&gt;
&lt;p&gt;
The way around this is to "interrupt" the services, so you must stop sql server, which
requires finding the process id (pid) and killing it via task manager or kill.exe;
rename the mdf and ldf of the database taking the extremely long recovery time and
then restart the services, everything should come on-line.&amp;nbsp; Now you can either
restore from a backup or re-attach the mdf / ldf and let it start recovering again....
&lt;/p&gt;
&lt;p&gt;
very very bad solution as interrupting sqlservr.exe with a kill of the pid is a high
risk operation that could corrupt other databases, so proceed with caution and get
a critical support case opened with Microsoft, you do not want to be doing this alone,
have them on the phone with you, severity 1.
&lt;/p&gt;
&lt;p&gt;
RESPONSE FROM MICROSOFT (Names removed)&amp;gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font face=Tahoma&gt;&lt;strong&gt;From:&lt;/strong&gt; [nameremoved@microsoft.com] 
&lt;br&gt;
&lt;b&gt;Sent:&lt;/b&gt; Friday, February 08, 2008 9:02 AM&lt;br&gt;
&lt;b&gt;To:&lt;/b&gt; Horkay, Robert&lt;br&gt;
&lt;b&gt;Cc:&lt;/b&gt;&amp;nbsp;&lt;br&gt;
&lt;b&gt;Subject:&lt;/b&gt; RE: Case number SRX080206600293 - SQLAgent will not start on a cluser
- Open&lt;br&gt;
&lt;br&gt;
&lt;/font&gt;
&lt;/p&gt;
&lt;div&gt;
&lt;/div&gt;
&lt;div class=Section1&gt;
&lt;p class=MsoNormal&gt;
&lt;span style="COLOR: blue"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;Hi
Bob,&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal&gt;
&lt;span style="COLOR: blue"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;span style="COLOR: blue"&gt;We have decided to file a design change request to
see if our development team will build in functionality to SQL Agent so that a registry
key, trace flag or some startup parameter can be added to have SQL Agent go ahead
and start up while databases are in recovery.&amp;nbsp; If this is approved then a knowledge
base article would be published describing how to do this and the caveats involved.&amp;nbsp;
Instead of taking SQL Server down to stop recovery we would only have to take SQL
Agent offline to add the required parameters to change the code path in SQL Agent
and let it start up immediately or at least 5 minutes after starting the service.&amp;nbsp;
I will continue to work on the design change request and hopefully it will be approved.&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal&gt;
&lt;span style="COLOR: blue"&gt;
&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/span&gt;&lt;span style="COLOR: blue"&gt;Thank you,&lt;/span&gt;&lt;span style="COLOR: black"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;div&gt;
&lt;p class=MsoNormal&gt;
&lt;b&gt;&lt;span style="FONT-SIZE: 18pt; COLOR: navy; FONT-FAMILY: Papyrus"&gt;{removed}&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style="COLOR: black"&gt;,&amp;nbsp; &lt;/span&gt;&lt;/b&gt;&lt;i&gt;&lt;span style="COLOR: green"&gt;MCDBA&lt;/span&gt;&lt;/i&gt;&lt;span style="COLOR: blue"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal&gt;
&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Calibri','sans-serif'"&gt;Microsoft
SQL Server Support Escalation Engineer&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal&gt;
&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: blue; FONT-FAMILY: 'Calibri','sans-serif'"&gt;SQL
Server Escalation Services Team&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal&gt;
&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: blue; FONT-FAMILY: 'Calibri','sans-serif'"&gt;Product
Support Services (PSS) - &lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&lt;?xml:namespace prefix = ns0 ns = "urn:schemas-microsoft-com:office:smarttags" /&gt;
&lt;ns0:place&gt;
&lt;ns0:City&gt;
&lt;ns0:place&gt;
&lt;ns0:City&gt;
&lt;span style="COLOR: blue"&gt;Charlotte&lt;/span&gt;
&lt;/ns0:City&gt;
&lt;/ns0:place&gt;
&lt;/ns0:City&gt;
&lt;span style="COLOR: blue"&gt;, &lt;/span&gt;
&lt;ns0:State&gt;
&lt;ns0:State&gt;
&lt;span style="COLOR: blue"&gt;NC&lt;/span&gt;
&lt;/ns0:State&gt;
&lt;/ns0:State&gt;
&lt;/ns0:place&gt;
&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;p class=MsoNormal&gt;
&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: blue; FONT-FAMILY: 'Calibri','sans-serif'"&gt;Hours:&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&amp;nbsp; &lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #c0504d; FONT-FAMILY: 'Garamond','serif'"&gt;M-F
9:00am - 6:00pm Eastern&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: blue; FONT-FAMILY: 'Calibri','sans-serif'"&gt; | &lt;b&gt;&lt;i&gt;Phone:&lt;/i&gt;&lt;/b&gt;&lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: purple; FONT-FAMILY: 'Calibri','sans-serif'"&gt;&amp;nbsp; &lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: #c0504d; FONT-FAMILY: 'Garamond','serif'"&gt;{Removed} &lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: blue; FONT-FAMILY: 'Calibri','sans-serif'"&gt;| &lt;/span&gt;&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: blue; FONT-FAMILY: 'Calibri','sans-serif'"&gt;Email:&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;b&gt;&lt;i&gt;&lt;span style="FONT-SIZE: 11pt; COLOR: black; FONT-FAMILY: 'Calibri','sans-serif'"&gt; {Removed}&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.lifeasbob.com/aggbug.ashx?id=c7cc343d-880d-4353-9547-25f66f775a68" /&gt;</description>
      <comments>http://www.lifeasbob.com/CommentView,guid,c7cc343d-880d-4353-9547-25f66f775a68.aspx</comments>
      <category>SQL Server / SQL Agent</category>
    </item>
  </channel>
</rss>