Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Fixing SQL Server Error 562: Failed to Access Critical Data Files

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step Fix
  3. If That Did Not Work
  4. Common Mistakes
  5. Tips
  6. Troubleshooting
  7. Frequently Asked Questions

SQL Server error 562—"Failed to access files" (specifically, system tables like `mdf`, `nlf`, or log files)—prevents your database from starting or maintaining connections. This error typically occurs when file permissions, corruption, or missing dependencies block access. Fixing it requires checking filesystem permissions, verifying file integrity, and ensuring the database engine has the correct privileges. The simplest workaround is restoring the corrupted files from a backup, but if you lack one, you’ll need to repair or recreate them step-by-step.

What You'll Need

  • Administrative rights on the SQL Server machine (domain/Windows credentials if remote).
  • The SQL Server instance (local or network) where the error occurs.
  • Access to the server’s file system (e.g., C:\Program Files\Microsoft SQL Server\Data for default installations).
  • (Optional) A backup of the database files if available (e.g., `.bak` or `.mdf` copies).
  • SQL Server Management Studio (SSMS), SQL Server Command Line Tool (`sqlcmd`), or PowerShell with SQL module installed.
  • Knowledge of your database’s file locations (check via `SELECT * FROM sys.master_files` in SSMS).

Step-by-Step Fix

  1. Restart the SQL Server Service Open Services (Win + R → *services.msc*), locate "SQL Server (Default)" or your instance name, right-click → Restart. If the service fails to start after restart, proceed to the next step.
  2. Check File Permissions Navigate to the SQL Server data folders (common paths: `C:\SQLServerData`, `Program Files\Microsoft SQL Server\Data`). Right-click the problematic file (e.g., `master.mdf`) → Properties → Security → Edit. Ensure the IIS_IUSRS or NT AUTHORITY\SYSTEM group has Full Control. If missing, add them and grant permissions. For remote installs, verify the network account used by SQL Server (e.g., SQLServiceAccount) has read/write access.
  3. Verify File Existence and Integrity Open Command Prompt as Administrator and run: dir "C:\SQLServerData\*.mdf" /a If files are missing, restore from backup or recreate them (see step 8). If files exist but SQL Server can’t access them, check:
    • No antivirus softlocks (temporarily exclude SQL Server folders).
    • Disk space (run `df -h` in PowerShell).
    • File attributes (delete read-only flags via Properties → Advanced → Uncheck "Read-only").
  4. Repair the Database via SSMS (If Files Are Corrupt) Open SSMS, connect to the server. Right-click the database → Tasks → Restore → Database. Select the source (e.g., device or file) with the corrupted file, choose Options → With Rebuild Master, and click OK. This won’t recover data but ensures SQL Server can start. If you lack backups, skip to step 8.
  5. Recreate the System Database Files If files are corrupted beyond repair, recreate them as follows:
    1. Stop the SQL Server service (Services.msc → right-click → Stop).
    2. Delete the old files (e.g., `master.mdf`, `master.log`).
    3. Recreate the logical files in SQL Server Configuration Manager:
      1. Open "SQL Server Configuration Manager," expand "SQL Server Network Configuration → Protocols for [Instance]."
      2. Right-click → Add Protocol for TCP/IP (if not already present).
      3. Enable TCP/IP and ensure it’s the default protocol.
    4. Create new system databases manually or use a script to rebuild them (example below).
    Script to Rebuild System Databases: CREATE DATABASE [master] ON PRIMARY ( NAME = N'master', FILENAME = N'C:\SQLServerData\master.mdf', SIZE = 10, FILEGROWTH = 5 ) LOG ON ( NAME = N'master_log', FILENAME = N'C:\SQLServerData\master_log.ldf', SIZE = 5, FILEGROWTH = 5 ); Repeat for `model`, `msdb`, and `tempdb`. Restart SQL Server after completing.
  6. Use `sqlcmd` to Force Start (Emergency Workaround) Open Command Prompt as Admin and run: sqlcmd -S [SERVER] -U [USER] -P [PASSWORD] -Q "ALTER DATABASE [DBNAME] SET EMERGENCY" Then start SQL Server manually to bypass corruption (temporary fix until files are restored). Do not use this if you lack backups.
  7. Reinstall SQL Server (Last Resort) If all else fails, reinstall SQL Server while preserving existing databases via backup. Recreate system databases as in step 8.

If That Did Not Work

If the service still fails after these steps: 1. **Check SQL Server Error Logs**: Open `C:\Program Files\Microsoft SQL Server\MSSQL[Version]\LOG\ERRORLOG` for details. 2. **Verify RAID/SAN Issues**: Corruption may stem from disk errors—run `chkdsk /f` on the drive hosting SQL files. 3. **Test File Access**: Use PowerShell to test permissions: icacls "C:\SQLServerData\master.mdf" /inheritance:r /grant:r "IIS_IUSRS" 4. **Contact Support**: If the error persists (e.g., "file not found" with exact paths), escalate to Microsoft Support with the raw error log.

Common Mistakes

  • Forgetting to Uncheck "Read-only" flags: Files marked read-only block SQL Server from accessing them. Always verify this in Properties → Advanced.
  • Insufficient Permissions: Granting only "Modify" instead of "Full Control" fails. Always use Full Control for system files.
  • Ignoring Antivirus Restrictions: Temporary exclusions are critical for critical files. Add the SQL Server folders to antivirus white-lists.
  • Recreating Logs Without Primary Files: Log files (`ldf`) require their `.mdf` counterpart. Delete either, and the operation fails.

Tips

  • Prevent Future Issues: Regularly check file permissions on SQL Server drives. Use `Get-ChildItem -Path "C:\SQLServerData" | Get-Acl` in PowerShell to audit permissions.
  • Backup Files Daily: For critical databases, schedule backups of `.mdf`/`.ldf` files outside the SQL Server folder.
  • Use SQL Server Agent for Monitoring: Set up alerts for failed database restarts or disk space warnings.
  • Check Disk Health: Run `fsutil dirty query C:` to detect disk fragmentation that may cause corruption.

Troubleshooting

  1. Error: "Cannot open database 'master' requested by the login"
    • Verify `master.mdf` exists in the correct path (default: `C:\SQLServerData`).
    • Use `sqlcmd` to manually start the database: sqlcmd -S [SERVER] -U sa -P [PASSWORD] -Q "USE master"
  2. Error: "Logical file 'NLF' cannot be opened because the physical file 'NLF' could not be opened"
    • Check if the `.ldf` file exists alongside its `.mdf`.
    • Recreate the logical file in the SQL Server instance configuration.
  3. SQL Server Starts but Logins Fail
    • Reset the login credentials using `ALTER LOGIN` in SSMS.
    • Ensure the login mapping in Windows matches the SQL Server account.
  4. Files Exist but Are "Not a Valid Database File"
    • Corruption check: Open PowerShell and run: SELECT name, physical_name FROM sys.master_files WHERE database_id = DB_ID('master')
    • If corrupted, restore from backup or recreate.

Frequently Asked Questions

Why does SQL Server error 562 occur?

This error signals a filesystem access failure, often caused by missing files, incorrect permissions, or corrupted data blocks. The exact trigger depends on the file type (e.g., `.mdf`, `.ldf`) and whether the system databases (`master`, `tempdb`) are involved.

How do I check which files SQL Server needs to start?

Run this query in SSMS: SELECT name, type_desc, state_desc FROM sys.master_files WHERE database_id = DB_ID('master') This lists all files required to start the database, including their current state (e.g., "Online" or "Corrupt").

Can I fix this without backups?

No. If you lack backups, recreating system databases requires rebuilding all files from scratch, which loses all user data. Always test in a non-production environment first.

What if SQL Server won’t start at all?

If the service fails to start after steps 1–5, check the error log for specific file paths. For example, an error like "Cannot open file C:\SQLServerData\master.mdf" indicates the file is missing or corrupted beyond repair.

How often should I monitor SQL Server file permissions?

Monitor permissions bi-weekly for critical databases. Use PowerShell scripts to compare user permissions (`Get-SQLLogonUser` in the SQLPS module) or schedule audits via SQL Server Agent.

Is there a way to test file integrity without SSMS?

Yes. Use `sqlcmd` to verify system databases: sqlcmd -S [SERVER] -U sa -P [PASSWORD] -Q "SELECT name FROM sys.databases WHERE state = 0" If this fails, the databases are corrupt or inaccessible.

What if the issue is on a remote server?

For remote installs, verify:
  • Network access to the SQL Server folder (e.g., mapped drive or SMB permissions).
  • The Windows Firewall allows SQL Server port (default: 1433).
  • The remote user account has local admin rights on the target server.
Use `Test-NetConnection` in PowerShell to confirm connectivity to the SQL Server port.