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

Troubleshooting Guide: SQL Server Error 6600 – “XML error: %.*ls”

Why This Error Happens

Error 6600 occurs when SQL Server’s XML parser encounters malformed, incomplete, or improperly encoded XML data during a parsing operation such as OPENXML, sp_xml_preparedocument, or an XML data type insert/cast. This is frequently caused by invalid characters, mismatched tags, or encoding mismatches (e.g., UTF-16 vs UTF-8) in the source XML document. It can also surface when a corrupted intermediate file or a truncated network payload is passed into the XML parsing engine on Windows Server 2025 / Windows 11 hosts.

Step-by-Step Resolution Guide

Step 1: Validate the Source XML Document

  • Extract the exact XML payload being passed to SQL Server (from the application log, sp_xml_preparedocument call, or input file).
  • Validate it using a strict XML validator (e.g., xmllint --noout file.xml or Visual Studio’s XML schema validator).
  • Check specifically for unclosed tags, unescaped special characters (&, <, >), and invalid namespace declarations.

Step 2: Confirm Encoding Compatibility

  • Open the XML source in a hex editor or Notepad++ and confirm the declared encoding (<?xml version="1.0" encoding="UTF-8"?>) matches the actual byte encoding (BOM markers).
  • If the file originates from a non-Windows system or legacy ETL process, re-save it as UTF-8 without BOM, or convert using PowerShell: Get-Content file.xml -Encoding UTF8 | Set-Content fixed.xml -Encoding UTF8.
  • Re-test the import against a local SQL Server 2025 instance to isolate whether the encoding was the trigger.

Step 3: Inspect the SQL Query and Parser Calls

  • Review stored procedures or application code using sp_xml_preparedocument, OPENXML, .query(), .value(), or CAST(... AS XML).
  • Ensure the XML document handle is not being reused incorrectly across sessions, and that sp_xml_removedocument is called to clear memory, since leftover handles can produce stale parser states.
  • Check for truncated variables — confirm that variables of type NVARCHAR(MAX) are used instead of NVARCHAR(4000) or smaller, since truncation at 4000 characters commonly breaks XML structure mid-tag.

Step 4: Apply Latest Cumulative Update

  • Open SQL Server Configuration Manager and confirm the current build version via SELECT @@VERSION;.
  • Download and apply the latest Cumulative Update (CU) for SQL Server 2025 from the Microsoft Update Catalog, as XML parser fixes are occasionally shipped in CUs.
  • Reboot the Windows Server 2025 / Windows 11 host after installation and re-run the failing query.

Alternative or Verification Steps

  • Run the corrected XML payload through SELECT CAST(@xmlVar AS XML); in SSMS — if it returns without error, the fix is confirmed.
  • As an alternative, wrap the XML ingestion logic in a TRY...CATCH block with sp_xml_preparedocument to capture and log the exact byte offset of the malformed XML for faster future diagnosis.