適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions) 適用範圍:Applies to: 是SQL ServerSQL Server (所有支援的版本) yesSQL ServerSQL Server (all supported versions)


屬性Attribute Value
產品名稱Product Name SQL ServerSQL Server
事件識別碼Event ID 1720417204
元件Component SQLEngineSQLEngine
訊息文字Message Text %ls:無法開啟檔案 %ls,檔案編號為 %d。%ls: Could not open file %ls for file number %d. 作業系統錯誤: %ls。OS error: %ls.


SQL Server 無法開啟指定的檔案,因為發生指定的 OS 錯誤。SQL Server was unable to open the specified file because of the specified OS error.

當 SQL Server 無法開啟資料庫和/或交易記錄檔時,您可能會在 Windows 應用程式事件或 SQL ServerSQL Server 錯誤記錄檔中看見錯誤 17204。You may see error 17204 in the Windows Application Event or the SQL ServerSQL Server Error log when SQL Server cannot open a database and/or transaction log files. 此錯誤的外觀範例如下所示:Here is an example of what the error may look like:

Error: 17204, Severity: 16, State: 1.
FCB::Open failed: Could not open file c:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\MSSQL\data\MyDB_Prm.mdf for file number 1.  OS error: 5(Access is denied.).

您可能會在 SQL ServerSQL Server 執行個體的啟動程序期間,或是嘗試啟動資料庫的任何 Database 作業 (例如 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). 在某些情況下,您可能會同時看見 17204 和 17207 錯誤,而在其他情況下則只看見其中一個錯誤。In some scenarios, you may see both 17204 and 17207 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 容錯移轉叢集資源離線。A failure with a system database could also result in a SQL ServerSQL Server failover cluster resource to go offline.


在可以使用任何 SQL ServerSQL Server 資料庫之前,該資料庫必須先啟動。Before any SQL ServerSQL Server database can be used, the database needs to be started. 資料庫啟動程序會涉及:The database startup process involves:

  1. 初始化代表資料庫及資料庫檔案的各種資料結構Initializing various data structures that represent the database and the database files
  2. 開啟屬於資料庫的所有檔案Opening all the files that belong to the database
  3. 在資料庫上執行復原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.

訊息 17204 (和 17207) 指出 SQL ServerSQL Server 在啟動程序期間嘗試開啟資料庫檔案時發生錯誤。Messages 17204 (and 17207) 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. 對應至檔案的檔案識別碼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. 解決錯誤 17204 須涉及了解相關聯的作業系統錯誤碼並診斷該錯誤。Resolving error 17204 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. 在那種情況下,您必須採取特定的矯正措施。Then, you have to take specific corrective actions. 我們將在此節中討論這些動作。We'll discuss these actions in this section.
  2. 如果 17204 錯誤訊息僅包含錯誤碼,而沒有錯誤描述,您可以嘗試從作業系統殼層使用命令來解決錯誤碼:net helpmsg If the 17204 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 錯誤碼? (英文) 之類的資訊來源,來將這些狀態碼解碼為 OS 錯誤。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 of 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 through 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, etc. - 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 Process Monitor (英文) 之類的工具,來了解檔案存取是否正在 SQL ServerSQL 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 ServerSQL Server instance service startup account [or Service SID] or an impersonated account.

      如果 SQL ServerSQL Server 正在模擬執行 ALTER DATABASE 或 CREATE DATABASE 作業之使用者的認證,您將會在 Process Monitor 工具 (作為範例) 中注意到下列資訊:If SQL ServerSQL Server is impersonating the credentials of the user that executes the ALTER DATABASE or CREATE DATABASE operation, you will notice the following information in the Process Monitor tool (an example):

      Event Class:        File System
      Operation:          CreateFile
      Result:                ACCESS DENIED
      Path:                  C:\Program Files\Microsoft SQL Server\MSSQL10.SQL2008\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. If you are getting The system cannot find the file specified OS error = 3:
    • Review the complete path from the error message
    • Ensure the disk drive and the folder path is visible and accessible from Windows Explorer
    • 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 topic Move Database Files. You may have to use this procedure, especially for system database files that encounter 17204 or 17207 and you are working through a disaster recovery scenario where the specified disk drives are unavailable. 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. For more information, refer to the OFFLINE section of the topic ALTER DATABASE File and Filegroup Options (Transact-SQL).
      • 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.
    • 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. If you're getting the The process cannot access the file because it is being used by another process operating system error = 32:
    • 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
    • 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 )
    • 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. Normally, this doesn't occur, but misconfigurations of the cluster or I/O paths can lead to such issues.