启动 SQL Server 服务时出现错误 1069

原始产品版本: SQL Server
原始 KB 数: 282254

概要

错误 1069:“由于登录失败,服务未启动”,当SQL Server或SQL Server 代理服务无法使用其配置的服务帐户登录时发生。 本文介绍如何解决系统事件日志条目显示服务控制管理器事件 ID 7041 或事件 ID 7038 时的错误 1069。 原因包括缺少“作为服务登录”权限、已禁用或锁定的帐户、过期或不正确的密码,以及启动期间无法访问的域。

症状

尝试重启Microsoft SQL Server 或SQL Server 代理时,服务不会启动,并且你会收到以下错误消息,具体取决于尝试启动服务的方式:

  • 通过使用服务小应用程序:

    Windows 无法在本地计算机上启动 SQL Server 服务。
    错误 1069:由于登录失败,服务未启动。

  • 使用命令提示符:

    系统错误 1069 已发生。
    由于登录失败,服务未启动。

你可能会在系统事件日志中找到事件 ID 为 7041 或 7038 的消息。

原因

出现此问题的原因是服务帐户本身存在问题,或者当前为服务帐户保存的信息存在问题。

哪个分辨率适用于事件 ID

使用系统事件日志中的事件 ID 和错误文本选择解决方法:

事件编号 事件中的错误文本 解决方案
7041 登录失败:用户未被授予在此计算机上所请求的登录类型。 事件 ID 7041 的解决方法
7038 此用户无法登录,因为此帐户当前已禁用。 账户已禁用
7038 登录前必须更改用户的密码。 必须更改密码
7038 用户名或密码不正确。 密码不正确或 gMSA 标志不正确
7038 所引用的帐户当前已锁定,可能无法登录。 帐户已锁定
7038 指定的域不存在,或无法访问。 无法联系到域

事件 ID 7041 的解决方法

系统事件日志中事件 ID 为 7041 的条目可能包含以下错误消息:

登录失败:未授予用户在此计算机上的所请求的登录类型。

事件日志中的完整消息条目如下所示:

Log Name:      System
Source:        Service Control Manager
Date:          <Datetime>
Event ID:      7041
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      <Server name>
Description:
The MSSQLSERVER service was unable to log on as NT Service\MSSQLSERVER with the currently configured password due to the following error:
Logon failure: the user has not been granted the requested logon type at this computer.

Service: MSSQLSERVER  
Domain and account: <AccountName>

This service account does not have the required user right "Log on as a service."

User Action

Assign "Log on as a service" to the service account on this computer. You can use Local Security Settings (Secpol.msc) to do this.
If this computer is a node in a cluster, check that this user right is assigned to the Cluster service account on all nodes in the cluster.

If you have already assigned this user right to the service account, and the user right appears to be removed,
check with your domain administrator to find out if a Group Policy object associated with this node might be removing the right.

若要解决此问题,请检查向 SQL Server 服务帐户分配了哪些用户权限。

  1. 启动 本地安全策略 管理单元(secpol.msc)。

  2. 展开 本地策略,然后选择 用户权限分配。

  3. 按照Windows特权和权限中的说明,验证是否已将所需的用户权限分配给服务帐户。 手动分配任何缺失的权限。

  4. 检查是否为服务帐户分配了任何拒绝类型的用户权限。 删除该 SQL Server 服务帐户的任何拒绝用户权限,然后重新测试。

    例如,如果为服务帐户分配了“拒绝作为服务登录”以及SeServiceLogonRightSeDenyServiceLogonRight,请撤销该登录的SeDenyServiceLogonRight权限并重启 SQL Server。

事件 ID 7038 的解决方法

在与事件 ID 7038 相关的日志条目中,你可能会发现以下错误消息:

此用户无法登录,因为此帐户当前已禁用

事件日志中的完整消息条目如下所示:

Log Name:      System
Source:        Service Control Manager
Date:          <Datetime>
Event ID:      7038
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      <Server name>
Description:
The MSSQLSERVER service was unable to log on as .\sqlsrvlogin with the currently configured password due to the following error:
This user can't sign in because this account is currently disabled.

To ensure that the service is configured properly, use the Services snap-in in Microsoft Management Console (MMC).

若要解决此问题,请根据方案使用以下方法之一:

  • 如果SQL Server启动帐户是计算机上的本地用户帐户,请打开计算机管理(compmgmt.msc),并检查服务帐户是否在本地用户和组中被禁用。 如果已禁用,请启用帐户并重启 SQL Server 服务。

  • 如果 SQL Server 启动帐户是 Windows 域帐户,请检查该帐户是否已在 Active Directory 用户和计算机 中被禁用。 如果已禁用,请启用帐户并重启 SQL Server 服务。

登录前必须更改用户的密码

事件日志中的完整消息条目如下所示:

Log Name:      System
Source:        Service Control Manager
Date:          <Datetime>
Event ID:      7038
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      <Server name>
Description:
The MSSQLSERVER service was unable to log on as .\sqlsrvlogin with the currently configured password due to the following error:
The user's password must be changed before signing in.

To ensure that the service is configured properly, use the Services snap-in in Microsoft Management Console (MMC).

若要解决此问题,请根据你的具体情况使用以下方法之一:

  • 如果SQL Server启动帐户是计算机上的本地用户帐户:

    1. 打开 计算机管理 (compmgmt.msc)。
    2. 选择“本地用户和组”,然后选择“用户”以找到该帐户。
    3. 双击用户帐户以打开其 属性。
    4. 清除 SQL Server 启动帐户的 “用户下次登录时必须更改密码” 属性,然后选择 确定。
    5. 重启 SQL Server 服务。
  • 如果SQL Server启动帐户是Windows域帐户:

    1. 在域控制器上打开Active Directory 用户和计算机。
    2. 在正确的域下选择“ 用户 ”。
    3. 双击用作SQL Server服务帐户的域帐户以打开其属性。
    4. 转到“帐户”选项卡,检查用户下次登录时必须更改密码是否已启用。 如果启用此选项,请清除此选项或以交互方式登录到 Windows 客户端计算机,然后设置新密码。
    5. 如果更改了密码,请使用 SQL Server 配置管理器 工具更新 SQL Server 服务的新密码。

用户名或密码不正确

对于不正确的密码问题,事件日志中的完整消息条目类似于以下条目:

Log Name:      System
Source:        Service Control Manager
Date:          <Datetime>
Event ID:      7038
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      <Server name>
Description:
The MSSQLSERVER service was unable to log on as .\sqlsrvlogin with the currently configured password due to the following error:
The user name or password is incorrect.

To ensure that the service is configured properly, use the Services snap-in in Microsoft Management Console (MMC).

若要解决此问题,请执行以下步骤:

方案 1:密码不正确

错误消息条目指示当前登录名或密码不正确。 若要验证并解决问题,请执行以下步骤:

  1. 使用 runas 选项测试服务帐户凭据:

    1. 打开 Windows 命令提示符。

    2. 运行下面的命令:

      runas /user:<localmachine>\<SQLServiceAccount> cmd
      
  2. 如果命令成功,请在SQL Server 配置管理器、服务、SQL Server 服务和此帐户中仔细键入相同的凭据。

  3. 如果命令失败并报告相同的问题,请重置Windows登录的密码。

  4. 如果 SQL Server 启动帐户是计算机上的本地用户帐户,请打开 计算机管理 (compmgmt.msc),并重置本地用户的密码。

  5. 如果 SQL Server 启动帐户是 Windows 域帐户,请打开Active Directory 用户和计算机,然后在Users下更新该帐户的密码。 更新凭据后,返回到SQL Server 配置管理器中的服务下的SQL Server,并输入相同的凭据。

  6. 重新启动 SQL Server 服务。

    若要在 SQL Server 主机计算机上的 SQL Server 服务帐户中输入正确的密码,请遵循 SCM 服务 - 更改所用帐户的密码 中的过程。

方案 2:gMSA IsManagedAccount 标志设置不当

如果使用组托管服务帐户(gMSA)运行 SQL Server 服务,并且给定服务的 IsManagedAccount 标志设置为 false,则缓存机密无效后,可能会立即收到服务控制管理器事件 ID 7038。

若要识别并解决问题,请执行以下步骤:

  1. 验证所使用的帐户是否为 gMSA 帐户。 仅在确认 gMSA 后继续。

    • 如果以下命令针对该帐户成功,则表示你使用的是 gMSA 帐户。
    • 如果因 Cannot find an object with identity: 'account' 而失败,则服务帐户不是 gMSA 帐户。
    Get-ADServiceAccount -Identity 'yourGmsaName' -Properties PasswordLastSet
    

    有关详细信息,请参阅 检查 gMSA 帐户。

  2. 在命令提示符中运行以下命令,并检查IsManagedAccount的状态。 所需的结果是 true。 如果为 false,请继续操作。

    sc qmanagedaccount <YourSQLServiceName>
    

    SQL Server 命名实例 SQLPROD 的示例:

    sc qmanagedaccount MSSQL$SQLPROD
    
  3. 根据需要将标志设置为 true。

    sc managedaccount <YourSQLServiceName> TRUE
    

    SQL Server 命名实例 SQLPROD 的示例:

    sc managedaccount MSSQL$SQLPROD TRUE
    
  4. 尝试再次启动服务。

有关特定于 gMSA 的更多故障排除步骤,请参阅使用 gMSA 的 SQL Server 服务启动失败故障排查。

引用的帐户当前已锁定,可能无法登录

事件日志中的完整消息条目如下所示:

Log Name:      System
Source:        Service Control Manager
Date:          <Datetime>
Event ID:      7038
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      <Server name>
Description:
The MSSQLSERVER service was unable to log on as .\sqlsrvlogin with the currently configured password due to the following error:
The referenced account is currently locked out and may not be logged on to.

To ensure that the service is configured properly, use the Services snap-in in Microsoft Management Console (MMC).

若要解决此问题,请根据方案使用以下方法之一:

  • 如果SQL Server启动帐户是计算机上的本地用户帐户:

    1. 打开 计算机管理 (compmgmt.msc),并转到 本地用户和组。 然后选择“用户”。
    2. 清除本地用户和组下 SQL Server 启动帐户的“帐户已锁定”复选框,然后选择“确定”。
    3. 重启 SQL Server 服务。
  • 如果SQL Server启动帐户是Windows域帐户:

    1. 在域控制器上,打开Active Directory 用户和计算机。
    2. 在 “用户” 下,双击“SQL Server 启动帐户”,然后转到 “帐户” 选项卡。
    3. 检查帐户是否已标记为已锁定。
    4. 如果帐户已锁定,请选中“ 解锁帐户 ”复选框,然后选择“ 确定”。 设置强密码。
    5. 然后在 SQL Server 配置管理器、Services 和 SQL Server 中,为 SQL Server 服务账户配置使用相同的凭据。
    6. 重新启动 SQL Server 服务。

指定的域不存在或无法访问

事件日志中的完整消息条目如下所示:

Log Name:      System
Source:        Service Control Manager
Date:          <Datetime>
Event ID:      7038
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      <Server name>
Description:
The MSSQLSERVER service was unable to log on as xxx with the currently configured password due to the following error:
The specified domain either does not exist or could not be contacted.

To ensure that the service is configured properly, use the Services snap-in in Microsoft Management Console (MMC).

若要解决此问题,请根据你的具体情况使用以下方法之一:

  • 将特定 Windows 服务器上的 SQL Server 配置为延迟启动,这可确保 Netlogon 等其他 Windows 服务先完成,SQL Server 启动时不会出现问题。 这是 SQL 安装程序从 SQL Server 2022 开始的默认配置。

  • 如果延迟启动选项无法解决你这种情况下的问题,请更改 SQL Server 服务的恢复选项。 指定“重启服务”作为失败选项的操作。 使用熟悉的服务控制管理器接口从管理工具的服务小程序执行此选项。

    • 不建议对 SQL 故障转移群集实例(FCI)或可用性组(AG)使用此选项,因为设置可能会导致自动故障转移方案出现延迟。
  • 如果上述两个选项都不可行,请在提升的命令行控制台中运行以下命令,将SQL Server服务配置为依赖于 Netlogon 服务:

    sc config <YourSQLServiceName> depend=keyiso/netlogon
    

    SQL Server 命名实例 SQLPROD 的示例:

    sc config MSSQL$SQLPROD depend=keyiso/netlogon