Troubleshooting Guide: SQL Server Error 3221 – ReadFileEx Incomplete Read
Why This Error Happens
Error 3221 occurs when SQL Server 2025 attempts to read a backup or database file via the ReadFileEx system function, but the operation returns fewer bytes than expected. This is typically caused by a corrupted or truncated backup file, an unstable storage connection (SAN/NAS/network share) interrupting the I/O operation, or antivirus/backup software locking the file mid-read. It can also occur if the file was still being written to by another process when SQL Server attempted access.
Step-by-Step Resolution Guide
Step 1: Verify File Integrity and Accessibility
- Confirm the file path referenced in the error (
%ls) exists and is not zero-byte or truncated. - Run
CHECKSUMvalidation during restore usingRESTORE VERIFYONLY FROM DISK = 'path\to\file.bak'to confirm the backup isn’t corrupted. - Check file properties in Windows Explorer or via PowerShell (
Get-Item "D:\Backups\file.bak" | Select Length) to ensure the size matches the expected backup size.
Step 2: Rule Out Storage and Network Instability
- If the file resides on a network share or SAN/NAS, test for packet loss or latency using
pingandTest-NetConnectionagainst the storage host. - Review Windows Event Viewer under Windows Logs > System for Disk, iSCSI, or NTFS warnings (Event ID 7, 11, or 51) occurring at the same timestamp as Error 3221.
- Move the backup/data file locally to a fast local SSD temporarily and retry the operation to isolate whether storage is the bottleneck.
Step 3: Exclude Antivirus and Backup Software Interference
- Add SQL Server data, log, and backup directories (e.g.,
D:\SQLData\,D:\SQLBackups\) to your antivirus exclusion list. - Disable third-party backup agents (e.g., Veeam, Commvault) temporarily during the SQL restore/backup window to confirm no file-locking conflict.
- Restart the SQL Server service (
net stop MSSQLSERVERthennet start MSSQLSERVER) after making exclusion changes.
Step 4: Check Disk Health and File System Errors
- Run
chkdsk D: /f /ron the volume hosting the SQL files (requires a reboot if the volume is in use). - Review the disk’s SMART status using
Get-PhysicalDisk | Get-StorageReliabilityCounterin PowerShell to check for pending sector failures. - If using a virtualized environment (Hyper-V/VMware), verify the virtual disk isn’t experiencing synthetic I/O timeouts in the hypervisor host logs.
Alternative or Verification Steps
- Re-run the original operation (
RESTORE DATABASEor backup job) and confirm Error 3221 no longer appears in the SQL Server Error Log (EXEC sp_readerrorlog). - If the error persists only on a specific file, attempt to restore from an earlier, known-good backup copy to confirm whether the issue is isolated to file corruption rather than environmental instability.