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

Microsoft SQL Server 2025 Troubleshooting Guide: Error 4859

Why This Error Happens

Error 4859 occurs when SQL Server’s bcp utility or BULK INSERT command parses an XML-based format file that is missing a mandatory attribute (such as SOURCE, NAME, or COLLATION) inside a <FIELD> or <COLUMN> element. This typically happens because the format file was manually edited, generated with an incompatible version of bcp, or truncated/corrupted during transfer between systems. Since SQL Server 2025 enforces stricter schema validation on format files than previous versions, older format files generated on legacy instances may fail validation even if they worked before.

Step-by-Step Resolution Guide

Step 1: Locate and Open the Problematic Format File

  • Identify the exact file path and line number referenced in the error message (e.g., C:\SQLData\FormatFiles\import.xml, line 12).
  • Open the file in a text editor (Notepad++, VS Code) rather than a binary/hex editor to preserve encoding.
  • Check the XML structure around the reported line number for a <FIELD> or <COLUMN> tag.

Step 2: Identify and Add the Missing Attribute

  • Compare the malformed element against a valid schema; a typical <FIELD> element requires ID, xsi:type, TERMINATOR, and MAX_LENGTH.
  • A typical <COLUMN> element requires SOURCE, NAME, and COLLATION (for character types).
  • Manually insert the missing attribute, for example:
<FIELD ID="3" xsi:type="CharTerm" TERMINATOR="\t" MAX_LENGTH="50"/>
<COLUMN SOURCE="3" NAME="CustomerName" xsi:type="SQLVARYCHAR"/>
  • Save the file in UTF-8 encoding without BOM corruption.

Step 3: Regenerate the Format File Using Native bcp (Recommended Fix)

  • Instead of hand-editing, regenerate the file cleanly using the updated SQL Server 2025 bcp executable:
bcp YourDatabase.dbo.YourTable format nul -c -x -f C:\SQLData\FormatFiles\import_new.xml -S YourServerName -T
  • This ensures all required attributes (COLLATION, xsi:type, SOURCE) are auto-populated correctly per the current schema version.
  • Replace the old format file reference in your BULK INSERT or bcp import script with the newly generated file.

Step 4: Validate XML Schema Compliance

  • Run the file through an XML validator or PowerShell to confirm it is well-formed:
[xml]$doc = Get-Content "C:\SQLData\FormatFiles\import_new.xml"
  • If PowerShell throws a parsing error, the file still has structural issues (unclosed tags, mismatched quotes) beyond the missing attribute.

Alternative or Verification Steps

  • Re-run the original BULK INSERT or bcp command using the corrected/regenerated format file and confirm the operation completes without Error 4859.
  • If the error persists, switch to the non-XML (classic) format file version by omitting the -x flag when regenerating with bcp, as the classic format is less strict and can serve as a temporary workaround while the XML file is audited.