blog community
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 '<jobname>' (<job_id>) cannot be run because the CmdExec subsystem failed to load.  The job has been suspended

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

Subsystem 'ActiveScripting' could not be loaded (reason: The specified module could not be found)
Subsystem 'CmdExec' could not be loaded (reason: The specified module could not be found)
Subsystem 'Snapshot' could not be loaded (reason: The specified module could not be found)
Subsystem 'LogReader' could not be loaded (reason: The specified module could not be found)
Subsystem 'Distribution' could not be loaded (reason: The specified module could not be found)
Subsystem 'Merge' could not be loaded (reason: The specified module could not be found)
Subsystem 'QueueReader' could not be loaded (reason: The specified module could not be found)
Subsystem 'ANALYSISQUERY' could not be loaded (reason: The specified module could not be found)
Subsystem 'ANALYSISCOMMAND' could not be loaded (reason: The specified module could not be found)
Subsystem 'SSIS' 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 

Moving (reinstalling) the server caused the directory of these DLL'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'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. 

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

SET NOCOUNT ON
DECLARE @SQLRoot NVARCHAR(512)

IF @@VERSION LIKE ('% 9.%')
BEGIN
    EXEC master.dbo.xp_instance_regread
      N'HKEY_LOCAL_MACHINE'
      ,N'SOFTWARE\Microsoft\MSSQLServer\Setup'
      ,N'SQLPath', @SQLRoot OUTPUT

    UPDATE msdb.dbo.syssubsystems
    SET subsystem_dll = @SQLRoot+RIGHT(subsystem_dll,LEN(subsystem_dll)-CHARINDEX('\MSSQL\binn\',subsystem_dll)-5)
    WHERE
      subsystem_dll NOT LIKE @SQLRoot + '%'
      AND subsystem_dll <> '[Internal]'

    IF @@ROWCOUNT > 0
    BEGIN
      PRINT 'Bad references found on '+@@SERVERNAME
      PRINT 'Server root: '+@SQLRoot
    END

END


Posted 14-11-2007 9:22 by BertrandR

Comments

Barry wrote re: Restoring MSDB across instances, a bad idea
on 04-12-2007 13:32

Hi there

I can't tell you how helpful this blog has been - I have been banging my head against this for a while now. Most sincere thanks - drinks are on me!

Barry again wrote re: Restoring MSDB across instances, a bad idea
on 04-12-2007 13:38

For any other readers I should add that error messages of the form

[125] Subsystem 'XXX' could not be loaded (reason: 126)

are caused by the same issue.

And you even wrote a script!!!

BertrandR wrote re: Restoring MSDB across instances, a bad idea
on 04-12-2007 13:50

Glad I could help !

The script is because I had to fix a lot of instances and I didn't want to bother finding out which ones to fix manually. So I rolled this script out over all our servers :)

Dmitry wrote re: Restoring MSDB across instances, a bad idea
on 14-01-2008 10:42

Thank you so much for the script.

Just a one question, after executing the script problem fixed, but after

restarting SQL Agent , opening also command line window from sqlagent90.exe and still to be opened.

What can be the reason?

thank you

Dmitry wrote re: Restoring MSDB across instances, a bad idea
on 14-01-2008 10:49

If I closing this window of Agent it restarting automatically and I get error at event viewer

-----------

SQLServerAgent Monitor successfully restarted SQLServerAgent after SQLServerAgent terminated unexpectedly.

----------

BertrandR wrote re: Restoring MSDB across instances, a bad idea
on 14-01-2008 10:59

Are you using services.msc or the configuration manager to start SQL agent ?

Dmitry wrote re: Restoring MSDB across instances, a bad idea
on 14-01-2008 11:01

services.msc

and when i'm starting service SQL Agent, now also opening this window

BertrandR wrote re: Restoring MSDB across instances, a bad idea
on 14-01-2008 11:19

I have no idea why you would get a popup window when starting SQL Agent, it has never happened to me before, does it give any extra information in the agent log ?

Dmitry wrote re: Restoring MSDB across instances, a bad idea
on 14-01-2008 11:34

It's a my mistake

Parameter "Allow service to interact with desktop" on SQL Agent was checked

:-) Thank you again for the script !

BertrandR wrote re: Restoring MSDB across instances, a bad idea
on 14-01-2008 11:38

Ah that explains it, good luck !

Brandon M wrote re: Restoring MSDB across instances, a bad idea
on 12-03-2008 20:10

Many thanks to you for not only the explanation of the problem, but for the script as well! I have been fighting these "stored path" problems for the last few days, but when this one happened, I found your page and my problem was solved immediately!

Thank you, thank you, thank you!

Ken wrote re: Restoring MSDB across instances, a bad idea
on 17-06-2008 23:17

Hi,

I am getting this

Message

[125] Subsystem 'ActiveScripting' could not be loaded (reason: The specified module could not be found)

I used your script and executed. But when I restart the sql server the error logs are giving the same error.

BertrandR wrote re: Restoring MSDB across instances, a bad idea
on 19-06-2008 9:12

Maybe your setup has something I didn't account for in the script. Do a select on msdb.dbo.syssubsystems and look for the DLL files on your setup, then modify the path's to the DLLs. Good luck !

DavidB wrote re: Restoring MSDB across instances, a bad idea
on 10-08-2008 19:34

You are a genius. Thank you.

Henning wrote re: Restoring MSDB across instances, a bad idea
on 25-10-2008 22:28

Thanks !

Josh wrote re: Restoring MSDB across instances, a bad idea
on 10-03-2009 21:41

I moved MSDBs across instances as well...in hindsight it was a bit more trouble than it was worth. Your fix saved my butt. Thanks

Paul wrote re: Restoring MSDB across instances, a bad idea
on 21-04-2009 16:34

We've moved/renamed many servers over the last couple of years running SQL 2000. It has the same problem as well. In particular, any scheduled jobs for SQL Agent will still reference the old server name. Manual update of system table is required.

Andrey wrote re: Restoring MSDB across instances, a bad idea
on 15-05-2009 12:23

thanks a lot!

Amit wrote re: Restoring MSDB across instances, a bad idea
on 28-10-2009 6:59

what a script mate.great...it wirks like magic...

Brian wrote re: Restoring MSDB across instances, a bad idea
on 03-12-2009 18:49

Thanks!  I appreciated the script!  Helped me out a lot!

AdolphH wrote re: Restoring MSDB across instances, a bad idea
on 07-12-2009 4:42

Restoring MSDB across instances is not necessarily a bad idea, as long as SQL is installed the same way on all servers.  I’ve always had good luck with that. Unfortunately, that did not happen this time, and your script prevented us from having to reinstall.

Thanks.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?
Enter code (required)
Powered by Community Server (Commercial Edition), by Telligent Systems