Troubleshooting Guide: SQL Server Error 3271 — “A Nonrecoverable I/O Error Occurred on File”
Why This Error Happens
Error 3271 occurs when SQL Server’s I/O subsystem fails to read from or write to a database file due to a low-level disk, controller, or filesystem fault that cannot be retried or recovered automatically. This is commonly caused by underlying storage hardware failure, a corrupted NTFS/ReFS volume, antivirus or backup software locking the file, or the storage path becoming unavailable (e.g., disconnected SAN/NAS, dismounted volume). It can also surface during backup or restore operations when the destination device runs out of space or loses connectivity mid-operation.
Step-by-Step Resolution Guide
Step 1: Identify the Affected File and Check SQL Server Error Log
- Open SQL Server Management Studio (SSMS) and run:
EXEC sp_readerrorlog 0, 1, '3271'; - Note the exact file path (
%ls) and the OS-level error message (%ls) reported alongside Error 3271. - Cross-reference the timestamp with Windows Event Viewer under Windows Logs > System and Application for Disk, Ntfs, or VDS warnings.
Step 2: Verify Disk and Volume Health
- Open an elevated Command Prompt and run:
chkdsk D: /f /r(replaceD:with the actual drive hosting the .mdf/.ldf/.bak file). - Check physical disk status via
Get-PhysicalDisk | Select DeviceId, HealthStatus, OperationalStatusin PowerShell. - If using Storage Spaces or a SAN/NAS, confirm the LUN or virtual disk is online and not in a degraded/predictive-failure state using Server Manager > File and Storage Services.
Step 3: Confirm File Accessibility and Permissions
- Ensure the SQL Server service account (e.g.,
NT Service\MSSQLSERVERor a custom domain account) has full read/write permissions on the data folder (typicallyC:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\DATA). - Confirm no other process (antivirus, backup agent, or file indexing service) has an exclusive lock on the .mdf/.ndf/.ldf file by checking with
Resource Monitor > Disktab. - Add SQL Server data/log directories to your antivirus exclusion list to prevent file-locking conflicts during I/O operations.
Step 4: Restore or Repair the Affected Database
- If the file is confirmed corrupted and the disk hardware is healthy, take the database offline:
ALTER DATABASE [YourDB] SET OFFLINE; - Restore from the most recent clean backup:
RESTORE DATABASE [YourDB] FROM DISK = 'E:\Backups\YourDB.bak' WITH REPLACE, RECOVERY; - If no clean backup exists, attempt
DBCC CHECKDB ('YourDB', REPAIR_ALLOW_DATA_LOSS)only as a last resort, after taking a full file-level backup of the current state.
Step 5: Relocate Database Files to Healthy Storage
- If the underlying volume is failing, move data/log files to a new healthy disk using:
ALTER DATABASE [YourDB] MODIFY FILE (NAME = YourDB_Data, FILENAME = 'F:\SQLData\YourDB.mdf'); - Take the database offline, physically move the files via
Move-Item, then bring it back online withALTER DATABASE [YourDB] SET ONLINE;
Alternative or Verification Steps
- Run
DBCC CHECKDB ('YourDB') WITH NO_INFOMSGS, ALL_ERRORMSGS;to confirm the database is fully consistent and no further I/O errors are logged. - Monitor the SQL Server error log and Windows Event Viewer for 24–48 hours post-fix; if Error 3271 recurs on the same physical disk, replace the storage hardware rather than continuing repairs at the software layer.