How to fix Error 4889 on Windows Server 2025 / Windows 11

Why This Error Happens

This error occurs when SQL Server attempts to read a file (such as a format file, bulk insert source file, or an external script) that it expects to be encoded in Unicode but which does not contain the required Byte-Order Mark (BOM) at the start of the file. SQL Server 2025 relies on the BOM (typically FF FE or FE FF) to correctly detect UTF-16 encoding during operations like BULK INSERT, OPENROWSET(BULK...), or executing .sql scripts via sqlcmd. If the file was saved using a plain ASCII/UTF-8-without-BOM encoding, or if it was corrupted/truncated during transfer, SQL Server cannot validate the encoding header and throws Error 4889.

Step-by-Step Resolution Guide

Step 1: Identify the Problematic File and Encoding

  • Locate the exact file path referenced in the error message (%ls placeholder in the actual error output).
  • Open the file in a hex editor or Notepad++ to check for the BOM. UTF-16 LE should start with FF FE; UTF-16 BE starts with FE FF.
  • If no BOM bytes are present, confirm the file is plain ASCII or UTF-8 without BOM — this is the root cause.

Step 2: Re-Save the File With a Proper Unicode BOM

  • Open the file in Notepad on Windows 11 / Windows Server 2025.
  • Use “File > Save As”, then in the encoding dropdown select “UTF-16 LE” (listed as “Unicode” in older Notepad versions).
  • Alternatively, use PowerShell to force the correct encoding:
  Get-Content "C:\ImportFiles\source.txt" | Set-Content -Encoding Unicode "C:\ImportFiles\source_fixed.txt"
  • Replace the original file path in your BULK INSERT, format file, or script reference with the newly saved file.

Step 3: Update the Format File or Import Statement (If Applicable)

  • If this error occurs during a BULK INSERT or bcp operation using a format file (.fmt), verify the format file itself also uses the correct encoding.
  • Regenerate the format file using bcp with the -w flag for wide (Unicode) character format:
  bcp YourDatabase.dbo.YourTable format nul -c -w -f C:\Formats\NewFormat.fmt -T
  • Re-run the import job pointing to the newly generated format file and corrected data file.

Step 4: Validate File Integrity and Permissions

  • Ensure the SQL Server service account has read permissions on the file’s directory (C:\ImportFiles\), since partial reads can sometimes present as BOM detection failures.
  • Confirm the file wasn’t truncated during an FTP/SFTP transfer by comparing file size against the source system.
  • Re-transfer the file using binary mode (not ASCII mode) if it originated from a Linux/Unix system.

Alternative or Verification Steps

  • Re-run the original BULK INSERT, OPENROWSET, or sqlcmd command after resaving the file — the operation should complete without Error 4889.
  • As a quick alternative, if BOM-enforcement isn’t required, modify the import statement to explicitly specify a non-Unicode codepage using DATAFILETYPE = 'char' instead of 'widechar', bypassing the BOM check entirely.