Restoring MSDB across instances, a bad idea

We've recently been migrating instances of SQL Server between different clusters in order to dismantle an old cluster. To move the jobs we've been copying the MSDB from the old instance to the new one by performing a restore and we didn't run into any problems …  until yesterday. A job that used CmdExec instead of a T-SQL jobstep wouldn't run, put the job in suspended state and give the following error:

Unable to start execution of step 1 (reason: The CmdExec subsystem failed to load [see the SQLAGENT.OUT file for details]; The job has been suspended).  The step failed.

Checking the agent log provided the following error message:

Step 1 of job &#39;<jobname>&#39; (<job_id>) cannot be run because the CmdExec subsystem failed to load.&nbsp; The job has been suspended

After further examination of the agent log I found the following startup errors:

Subsystem &#39;ActiveScripting&#39; could not be loaded (reason: The specified module could not be found)
Subsystem &#39;CmdExec&#39; could not be loaded (reason: The specified module could not be found)
Subsystem &#39;Snapshot&#39; could not be loaded (reason: The specified module could not be found)
Subsystem &#39;LogReader&#39; could not be loaded (reason: The specified module could not be found)
Subsystem &#39;Distribution&#39; could not be loaded (reason: The specified module could not be found)
Subsystem &#39;Merge&#39; could not be loaded (reason: The specified module could not be found)
Subsystem &#39;QueueReader&#39; could not be loaded (reason: The specified module could not be found)
Subsystem &#39;ANALYSISQUERY&#39; could not be loaded (reason: The specified module could not be found)
Subsystem &#39;ANALYSISCOMMAND&#39; could not be loaded (reason: The specified module could not be found)
Subsystem &#39;SSIS&#39; could not be loaded (reason: The specified module could not be found)

As it turns out, SQL agent stores a path name to the DLL files required to perform the non T-SQL jobsteps in the MSDB. This is documented here: Microsoft KB 903205&nbsp;

Moving (reinstalling) the server caused the directory of these DLL&#39;s to change (in this case from MSSQL.6 to MSSQL.12) and the agent was unable to load them. As we rarely use any non T-SQL jobsteps we hadn&#39;t run into this problem yet.

The solution was performing an update to the msdb.dbo.syssubsystems table updating the values of subsystem_dll column to the current situation and restarting the agent.&nbsp;

EDIT: It appears only SQL 2005 is affected, SQL 2000 doesn&#39;t store these references in the MSDB. I&#39;ve compiled a script to fix wrong references:

SET NOCOUNT ON
DECLARE @SQLRoot NVARCHAR(512)

IF @@VERSION LIKE (&#39;% 9.%&#39;)
BEGIN
&nbsp; &nbsp; EXEC master.dbo.xp_instance_regread
&nbsp; &nbsp; &nbsp; N&#39;HKEY_LOCAL_MACHINE&#39;
&nbsp;&nbsp; &nbsp;&nbsp; ,N&#39;SOFTWAREMicrosoftMSSQLServerSetup&#39;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,N&#39;SQLPath&#39;, @SQLRoot OUTPUT

&nbsp;&nbsp;&nbsp; UPDATE msdb.dbo.syssubsystems
&nbsp;&nbsp;&nbsp;
SET subsystem_dll = @SQLRoot+RIGHT(subsystem_dll,LEN(subsystem_dll)-CHARINDEX(&#39;MSSQLbinn&#39;,subsystem_dll)-5)
&nbsp;&nbsp;&nbsp; WHERE
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
subsystem_dll NOT LIKE @SQLRoot + &#39;%&#39;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
AND subsystem_dll <> &#39;[Internal]&#39;

&nbsp; &nbsp; IF @@ROWCOUNT > 0
&nbsp;&nbsp;&nbsp; BEGIN
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRINT &#39;Bad references found on &#39;+@@SERVERNAME
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PRINT &#39;Server root: &#39;+@SQLRoot
&nbsp;&nbsp;&nbsp; END

END