FIX: SQL Server Agent job fails if you set the job schedule type as "Start automatically when SQL Server Agent starts" in SQL Server 2008 SP2, SQL Server 2008 SP3, SQL Server 2008 R2 SP1 or SQL Server 2008 R2 SP2

Article translations Article translations
Article ID: 2640027 - View products that this article applies to.
Expand all | Collapse all
Microsoft distributes Microsoft SQL Server 2008 SP2 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 SP2 fix release.

Symptoms

Consider the following scenario:
  • You do one of the following
    • Install Cumulative Update 2 for Microsoft SQL Server 2008 Service Pack 2 (SP2) or a later version of the cumulative update package
    • Upgrade SQL Server 2008 to SQL Server 2008 Service Pack 3 (SP3)
    • Upgrade SQL Server 2008 R2 to SQL Server 2008 R2 Service Pack 1 (SP1) or a later version of the service pack
  • You create a SQL Server Agent job on a user database, and you set the schedule type as Start automatically when SQL Server Agent starts.
  • You restart the SQL Server service.
In this scenario, the SQL Server Agent job fails.

Cause

This issue occurs because the user database is not finished recovering when the job starts. After you install Cumulative Update 2 for SQL Server 2008 SP2 or you upgrade SQL Server 2008 to SQL Server 2008 SP3 or you upgrade SQL Server 2008 R2 to SQL Server 2008 R2 SP1, SQL Server Agent starts just after the MSDB databases finish recovering.

Note SQL Server Agent should start after all the databases have recovered.

Resolution

SQL Server 2008 R2 Service Pack 1

The fix for this issue was first released in Cumulative Update 9. For more information about how to obtain this cumulative update package for SQL Server 2008 R2 Service Pack 1, click the following article number to view the article in the Microsoft Knowledge Base:
2756574 Cumulative update package 9 for SQL Server 2008 R2 Service Pack 1
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 R2 Service Pack 1 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
2567616 The SQL Server 2008 R2 builds that were released after SQL Server 2008 R2 Service Pack 1 was released

SQL Server 2008 Service Pack 3

The fix for this issue was first released in Cumulative Update 7 for SQL Server 2008 Service Pack 3. For more information about how to obtain this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:
2738350 Cumulative Update package 7 for SQL Server 2008 Service Pack 3
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 Service Pack 3 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
2629969 The SQL Server 2008 builds that were released after SQL Server 2008 Service Pack 3 was released

Cumulative Update 8 for SQL Server 2008 Service Pack 2

The fix for this issue was first released in Cumulative Update 8 for SQL Server 2008 Service Pack 2. For more information about how to obtain this cumulative update package for SQL Server 2008 Service Pack 2, click the following article number to view the article in the Microsoft Knowledge Base:
2648096 Cumulative update package 8 for SQL Server 2008 Service Pack 2
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 Service Pack 2 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
2402659 The SQL Server 2008 builds that were released after SQL Server 2008 Service Pack 2 was released

SQL Server 2008 R2 Service Pack 2

The fix for this issue was first released in Cumulative Update 2 for SQL Server 2008 R2 Service Pack 2. For more information about how to obtain this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:
2740411 Cumulative Update package 2 for SQL Server 2008 R2 Service Pack 2
Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 R2 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
2730301 The SQL Server 2008 R2 builds that were released after SQL Server 2008 R2 Service Pack 2 was released

Registry key information

Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
322756 How to back up and restore the registry in Windows
After you apply this hotfix, you must first restart the SQL Server Agent service for the affected instance. A new RecoveredDatabasesForAgentStartup registry key is created when the service restarts. This registry key defines whether SQL Server Agent waits for the recovery of the User databases to complete before it starts the SQL Server Agent job.

To have us configure this registry key for you, go to the "Fix it for me" section. If you prefer to configure this registry key yourself, go to the "Let me fix it myself" section.

Fix it for me



To configure this registry key automatically, click the Fix it button or link. Then click Run in the File Download dialog box, and follow the steps in the Fix it wizard.


Fix this problem
Microsoft Fix it 50868


Notes
  • Before you run this Fix it solution, you must install the hotfix that is described in Microsoft Knowledge Base (KB) article 2648096. Then, you must restart the SQL Server Agent service for the affected instance.
  • This wizard may be in English only. However, the automatic fix also works for other language versions of Windows.
  • If you are not on the computer that has the problem, save the Fix it solution to a flash drive or a CD and then run it on the computer that has the problem.

Then, go to the "Did this fix the problem?" section.



Let me fix it myself

To configure RecoveredDatabasesForAgentStartup registry key, follow these steps:
  1. Click Start, click Run, type regedit in the Open box, and then click OK.
  2. Locate and then click the following registry subkey:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.instance\SQLServerAgent\
  3. In the Details pane, right-click RecoveredDatabasesForAgentStartup, and then click Modify.
  4. In the Value data box, type ALL.

    Note The default value of the RecoveredDatabasesForAgentStartup registry entry is MSDB.
  5. Exit Registry Editor.
Note If you set the value of the RecoveredDatabasesForAgentStartup registry entry to a value that is not MSDB or ALL, a warning message is logged in the SQL Server Agent log, and SQL Server Agent waits only for the MSDB database.

Did this fix the problem?

  • Check whether the problem is fixed. If the problem is fixed, you are finished with this section. If the problem is not fixed, you can contact support.
  • We would appreciate your feedback. To provide feedback or to report any issues with this solution, please leave a comment on the "Fix it for me" blog or send us an email.

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Workaround

To work around this issue, add a step to the SQL Server Agent job that checks whether the targeted databases are online. This step should be the first step.

Note You can check the database status by querying the column state in the sys.databases system table.

Properties

Article ID: 2640027 - Last Review: October 15, 2012 - Revision: 8.0
Applies to
  • Microsoft SQL Server 2008 Enterprise
  • Microsoft SQL Server 2008 Developer
  • Microsoft SQL Server 2008 Service Pack 2
  • Microsoft SQL Server 2008 Service Pack 3
  • Microsoft SQL Server 2008 Standard
  • Microsoft SQL Server 2008 R2 Service Pack 2
Keywords: 
kbqfe kbfix kbexpertiseadvanced kbsurveynew kbfixme kbmsifixme KB2640027

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com