MSSQLSERVER_17207MSSQLSERVER_17207

适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions) 适用于:Applies to: 是SQL ServerSQL Server(所有支持的版本)yesSQL ServerSQL Server (all supported versions)

详细信息Details

AttributeAttribute Value
产品名称Product Name SQL ServerSQL Server
事件 IDEvent ID 1720717207
事件源Event Source MSSQLSERVERMSSQLSERVER
组件Component SQLEngineSQLEngine
符号名称Symbolic Name DBLKIO_OS2DISKERRORDBLKIO_OS2DISKERROR
消息正文Message Text %ls:创建或打开文件 '%ls' 时出现操作系统错误 %ls。%ls: Operating system error %ls occurred while creating or opening file '%ls'. 请诊断并更正该操作系统错误,然后重试操作。Diagnose and correct the operating system error, and retry the operation.

说明Explanation

SQL ServerSQL Server 由于指定的 OS 错误而无法打开指定的文件。was unable to open the specified file because of the specified OS error.

SQL ServerSQL Server 无法打开数据库和/或事务日志文件时,Windows 应用程序事件或 SQL ServerSQL Server 错误日志中可能会出现错误 17207。You may see error 17207 in the Windows Application Event or the SQL ServerSQL Server Error log when SQL ServerSQL Server cannot open a database and/or transaction log files. 此错误如以下示例所示。Here is an example of what the error may look like.

Error: 17207, Severity: 16, State: 1.
FileMgr::StartSecondaryDataFiles: Operating system error 2(The system cannot find the file specified.) occurred while creating or opening file 'F:\MSSQL\DATA\MyDB_FG1_1.ndf'. Diagnose and correct the operating system error, and retry the operation.

SQL ServerSQL Server 实例启动过程中,或在尝试启动数据库的任何数据库操作(如 ALTER DATABASE)期间,都可能看到这些错误。You may see these errors during the SQL ServerSQL Server instance startup process or any database operation that attempts to start the database (for example, ALTER DATABASE). 在某些情况下,你可能会看到 17207 和 17204 错误,而在其他情况下,你可能只会看到其中一种错误。In some scenarios, you may see both 17207 and 17204 errors and in other occasions you might just see one of them.

如果用户数据库遇到这些错误,该数据库将处于 RECOVERY_PENDING 状态,并且应用程序无法访问数据库。If a user database runs into these errors, that database will be left in the RECOVERY_PENDING state, and applications cannot access the database. 如果系统数据库遇到这些错误,则 SQL ServerSQL Server 实例将不会启动,并且你无法连接到 SQL ServerSQL Server 的此实例。If a system database encounters these errors, the SQL ServerSQL Server instance will not start and you cannot connect to this instance of SQL ServerSQL Server. 这也可能导致 SQL ServerSQL Server 故障转移群集资源脱机。This could also result in a SQL ServerSQL Server failover cluster resource to go offline.

如果问题与 SQL ServerSQL Server 文件流文件组相关,你将注意到仅列出了完整目录路径,而不是文件名。If the problem is related to your SQL ServerSQL Server FileStream filegroup, then you will notice that only the full directory path is listed instead of a file name. 以下是一个示例。Here is an example.

Error: 17207, Severity: 16, State: 1.
STREAMFCB::Startup: Operating system error 2(The system cannot find the file specified.) occurred while creating or opening file 'C:\Program Files\Microsoft SQL Server\MSSQL13.SQL2016\MSSQL\DATA\bpa_files_test_fs_1\bpa_files_test_fs_1'. Diagnose and correct the operating system error, and retry the operation.

原因Cause

在使用任何 SQL ServerSQL Server 数据库之前,必须启动数据库。Before any SQL ServerSQL Server database can be used, the database needs to be started. 数据库启动过程涉及初始化各种数据结构(这些结构表示数据库和数据库文件),打开属于数据库的所有文件,最后在数据库上运行恢复。The database startup process involves initializing various data structures that represent the database and the database files, opening all the files that belong to the database, and finally running recovery on the database. SQL ServerSQL Server 使用 CreateFile Windows API 函数打开属于数据库的文件。uses the CreateFile Windows API function to open the files that belong to a database.

消息 17207(和 17204)指示 SQL ServerSQL Server 尝试在启动过程中打开数据库文件时遇到错误。Messages 17207 (and 17204) indicate that an error was encountered while SQL ServerSQL Server attempted to open the database files during the startup process.

这些错误消息包含下列信息:These error messages contain the following information:

  1. 尝试打开文件的 SQL ServerSQL Server 函数的名称。Name of the SQL ServerSQL Server function that is attempting to open the file. 通常在这些错误消息中看到如下函数名称:The function name that you normally observe in these error messages is one of the following:

    • FCB::Open - 在 SQL ServerSQL Server 尝试打开文件时遇到错误FCB::Open - file has encountered an error when SQL ServerSQL Server attempts to open it
    • FileMgr::StartPrimaryDataFiles - 主数据文件或属于主文件组的文件FileMgr::StartPrimaryDataFiles - a primary data file or a file belonging to the primary file group
    • FileMgr::StartSecondaryDataFiles - 属于辅助文件组的文件FileMgr::StartSecondaryDataFiles - a file belonging to a secondary file group
    • FileMgr::StartLogFiles - 事务日志文件FileMgr::StartLogFiles - a transaction log file
    • STREAMFCB::Startup - SQL FileStream 容器STREAMFCB::Startup - SQL FileStream container
    • FCB::RemoveAlternateStreamsFCB::RemoveAlternateStreams
  2. 状态信息,用于区分可生成此错误消息的函数中的多个位置。The state information distinguishes multiple locations within a function that can generate this error message.

  3. 文件的完整物理路径。The full physical path for the file.

  4. 对应于文件的文件 ID。The file ID corresponding to the file.

  5. 操作系统错误代码和错误说明。The operating system error code and error description. 在某些情况下,只会看到错误代码。In some instances, you'll see only the error code.

在这些错误消息中输出的操作系统错误信息是导致错误 17204 的根本原因。The operating system error information printed in these error messages is the root cause leading to error 17204. 这些错误消息的常见原因是权限问题或文件路径不正确。Common causes for these error messages are a permission issue or an incorrect path to the file.

用户操作User action

  1. 要解决错误 17207,需要了解关联的操作系统错误代码并诊断该错误。Resolving error 17207 involves understanding the associated operating system error code and diagnosing that error. 解决了操作系统错误后,可以尝试重启数据库(例如,使用 ALTER DATABASE SET ONLINE)或 SQL ServerSQL Server 实例,使受影响的数据库处于联机状态。Once the operating system error condition is resolved, then you can attempt to restart the database (using ALTER DATABASE SET ONLINE, for example) or the SQL ServerSQL Server instance to bring the affected database online. 在某些情况下,可能无法解决操作系统错误,因此必须采取特定的纠正措施。In some cases, you may not be able to resolve the operating system error, so you will have to take specific corrective actions. 本节将介绍这些操作。We'll discuss these actions in this section.

  2. 如果 17207 错误消息只包含错误代码,而不包含错误说明,则可以尝试在操作系统 shell 中运行以下命令来解析错误代码:net helpmsg If the 17207 error message contains only an error code and not an error description, then you can try resolving the error code using the command from an operating system shell: net helpmsg . 如果收到的错误代码是一个 8 位数状态代码,可以参考如何将 HRESULT 转换为 Win32 错误代码?之类的信息源解码这些状态代码,了解它们在操作系统中都代表什么错误。If you are getting an 8-digit status code as the error code, then you can refer to the information sources like How do I convert an HRESULT to a Win32 error code? to decode what these status codes into OS errors.

  3. 如果收到 Access is Denied 操作系统错误 = 5,请考虑使用以下方法:If you are getting the Access is Denied operating system error = 5, consider these methods:

    • 通过在 Windows 资源管理器中查看文件的属性,检查文件的权限设置。Check the permissions that are set on the file by looking at the properties of the file in Windows Explorer. SQL ServerSQL Server 使用 Windows 组对各种文件资源预配访问控制。uses Windows groups to provision access control on the various file resources. 确保相应的组(名称类似于 SQLServerMSSQLUser$ComputerName$MSSQLSERVER 或 SQLServerMSSQLUser$ComputerName$InstanceName)具有对错误消息中提及的数据库文件的必要权限。Make sure the appropriate group (with names like SQLServerMSSQLUser$ComputerName$MSSQLSERVER or SQLServerMSSQLUser$ComputerName$InstanceName) has the required permissions on the database file that is mentioned in the error message. 有关更多详细信息,请参阅配置数据库引擎访问的文件系统权限Review Configure File System Permissions for Database Engine Access for more details. 确保 Windows 组实际包含 SQL ServerSQL Server 服务启动帐户或服务 SID。Ensure that the Windows group actually includes the SQL ServerSQL Server service startup account or the service SID.

    • 查看当前正在运行 SQL ServerSQL Server 服务的用户帐户。Review the user account under which the SQL ServerSQL Server service is currently running. 可以使用 Windows 任务管理器来获取此信息。You can use the Windows Task Manager to get this information. 查找可执行文件“sqlservr.exe”的“用户名”值。Look for the "User Name" value for the executable "sqlservr.exe". 另外,如果你最近更改了 SQL ServerSQL Server 服务帐户,请注意,支持执行此操作的方法是使用 SQL Server 配置管理器实用工具。Also if you recently changed the SQL ServerSQL Server service account, know that the supported way to do this operation is to use the SQL Server Configuration Manager utility. 有关详细信息,请参阅 SQL Server 配置管理器More information on this is available at SQL Server Configuration Manager.

    • 根据操作类型(在服务器启动期间打开数据库、附加数据库、还原数据库等),用于模拟和访问数据库文件的帐户可能会有所不同。Depending on the type of operation (opening databases during server startup, attaching a database, database restore, and so on), the account that is used for impersonation and accessing the database file may vary. 请查看保护数据和日志文件主题,了解哪些操作为哪些帐户设置了哪些权限。Review the topic Securing Data and Log Files to understand which operation sets what permission and to which accounts. 使用 Windows SysInternals 进程监视器之类的工具,了解是否在 SQL Server 实例服务启动帐户(或服务 SID)或模拟帐户的安全上下文中执行了文件访问。Use a tool like Windows SysInternals Process Monitor to understand if the file access is happening under the security context of the SQL Server instance service startup account (or Service SID) or an impersonated account.

      如果 SQL Server 正在模拟可执行 ALTER DATABASE 或 CREATE DATABASE 操作的登录用户凭据,你将在进程监视器工具(示例)中注意到以下信息。If SQL Server is impersonating the user credentials of the login that executes the ALTER DATABASE or CREATE DATABASE operation, you will notice the following information in the Process Monitor tool (an example).

      Date & Time:      3/27/2010 8:26:08 PM
      Event Class:        File System
      Operation:          CreateFile
      Result:                ACCESS DENIED
      Path:                  C:\Program Files\Microsoft SQL Server\MSSQL13.SQL2016\MSSQL\DATA\attach_test.mdf
      TID:                   4288
      Duration:             0.0000366
      Desired Access:Generic Read/Write
      Disposition:        Open
      Options:            Synchronous IO Non-Alert, Non-Directory File, Open No Recall
      Attributes:          N
      ShareMode:       Read
      AllocationSize:   n/a
      Impersonating: DomainName\UserName
      
  4. 如果遇到 The system cannot find the file specified OS 错误 = 3:If you are getting The system cannot find the file specified OS error = 3:

    • 查看错误消息中的完整路径。Review the complete path from the error message.
    • 确保磁盘驱动器和文件夹路径可见并可从 Windows 资源管理器访问。Ensure the disk drive and the folder path is visible and accessible from Windows Explorer.
    • 查看 Windows 事件日志,以确定此磁盘驱动器是否存在任何问题。Review the Windows Event log to find out if any problems exist with this disk drive.
    • 如果路径不正确并且该数据库已经存在于系统中,则可以使用移动数据库文件文章中所述的方法更改数据库文件路径。If the path is incorrect and if this database already exists in the system, you can change the database file paths using the methods explained in the Move Database Files article. 你可能必须使用此过程,尤其是对于遇到 17204 或 17207 的系统数据库文件,并且你正在使用指定磁盘驱动器不可用的灾难恢复方案。You may have to use this procedure, especially for system database files which encounter 17204 or 17207 and you are working through a disaster recovery scenario where the specified disk drives are unavailable. 本主题还介绍了如何识别各种系统数据库[master、model、tempdb、msdb 和 mssqlsystemresource]的当前位置。This topic also explains how you can identify the current location of the various system databases [master, model, tempdb, msdb and mssqlsystemresource].
    • 如果由于缺少数据库文件而出现此错误,则必须从有效备份还原数据库:If you see this error because the database files are missing, you have to restore the database from a valid backup:
      • 如果与错误关联的数据库文件属于辅助文件组,则可以选择将该文件组标记为脱机,使数据库联机,然后单独执行该文件组的还原。If the database file associated with the error belongs to a secondary filegroup, then you can optionally mark that filegroup offline, bring the database online, and then perform a restore of that filegroup alone. 有关详细信息,请参阅主题 ALTER DATABASE 文件和文件组选项 (Transact-SQL) 的脱机部分。For more information, refer to the OFFLINE section of the topic ALTER DATABASE File and Filegroup Options (Transact-SQL).
      • 如果产生错误的文件是一个事务日志文件,请查看主题 CREATE DATABASE (Transact-SQL) 中“FOR ATTACH”和“FOR ATTACH_REBUILD_LOG”部分下的信息,以了解如何重新创建丢失的事务日志文件。If the file that produced the error is a transaction log file, review the information under the sections "FOR ATTACH" and "FOR ATTACH_REBUILD_LOG" of the topic CREATE DATABASE (Transact-SQL) to understand how you can recreate the missing transaction log files.
    • SQL ServerSQL Server 尝试访问这些位置上的数据库文件之前,请确保任何磁盘或网络位置[如 iSCSI 驱动器]可用。Ensure that any disk or network location [like iSCSI drive] is available before SQL ServerSQL Server attempts to access the database files on these locations. 如果需要,请在群集管理员或服务控制管理器中创建所需的依赖项。If needed create the required dependencies in Cluster Administrator or Service Control Manager.
  5. 如果遇到 The process cannot access the file because it is being used by another process 操作系统错误 = 32:If you're getting the The process cannot access the file because it is being used by another process operating system error = 32:

    • 使用 Windows Sysinternals 中的进程资源管理器句柄之类的工具来确定其他进程或服务是否已获取此数据库文件的排他锁。Use a tool like Process Explorer or Handle from Windows Sysinternals to find out if another process or service has acquired exclusive lock on this database file.
    • 阻止该进程访问 SQL ServerSQL Server 数据库文件。Stop that process from accessing SQL ServerSQL Server Database files. 常见示例包括防病毒程序(请参阅以下知识库文章中的文件排除指南)。Common examples include anti-virus programs (see guidance for file exclusions in the following KB article).
    • 在群集环境中,确保前一个所属节点中的 sqlservr.exe 进程实际上已经将句柄释放到数据库文件。In a cluster environment, make sure that the sqlservr.exe process from the previous owning node has actually released the handles to the database files. 通常不会发生这种情况,但群集或 I/O 路径的错误配置可能会导致此类问题。Normally this doesn't occur, but misconfigurations of the cluster or I/O paths can lead to such issues.