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

Troubleshooting Guide: SQL Server Error 9460 — XML Parsing Error

Why This Error Happens

Error 9460 occurs when SQL Server’s native XML parser encounters malformed, incomplete, or invalid XML data that does not conform to well-formed XML syntax rules. This is typically caused by corrupted data during transmission, improperly escaped special characters (such as unescaped ampersands or angle brackets), or truncated XML strings due to column size limitations or application-layer encoding issues. It can also surface when a mismatch exists between the expected XML schema collection and the actual data being inserted or queried.

Step-by-Step Resolution Guide

Step 1: Identify the Exact Line and Source of the Malformed XML

  • Run the failing query in SQL Server Management Studio (SSMS) and capture the full error message, noting the specific line number referenced.
  • Use SELECT CAST(YourXMLColumn AS NVARCHAR(MAX)) to manually inspect the raw XML content near the reported line.
  • Check for unescaped characters like &, <, >, or improperly closed tags.

Step 2: Validate XML Against Schema and Encoding Standards

  • Confirm the XML data uses proper entity encoding (e.g., &amp; instead of &).
  • If using an XML Schema Collection, verify compatibility with SELECT * FROM sys.xml_schema_collections;.
  • Re-validate the source application (e.g., .NET, Java, or ETL tool) to ensure it is generating UTF-8 or UTF-16 compliant XML before insertion.

Step 3: Check for Data Truncation Issues

  • Inspect the source column or variable type; ensure NVARCHAR(MAX) or XML data types are used instead of restrictively sized VARCHAR(n) fields.
  • On Windows Server 2025/Windows 11, check the application’s connection string parameters for Packet Size limitations that might truncate large XML payloads mid-transmission.
  • Increase network packet size temporarily via sp_configure 'network packet size' if large XML documents are involved.

Step 4: Re-Import or Reconstruct the XML Document

  • If the XML originates from an external file, open it in a validator (like an XML editor or Visual Studio) to pinpoint syntax errors.
  • Correct the malformed node, re-save the file in UTF-8 encoding without BOM, and re-attempt the import.

Alternative or Verification Steps

  • Verify the fix by re-running the original INSERT, UPDATE, or SELECT statement that triggered Error 9460; a successful execution confirms the XML is now well-formed.
  • As an alternative, use TRY_CAST or TRY_CONVERT in a diagnostic query to isolate specific rows with invalid XML without halting the entire batch operation, allowing you to clean data in bulk before re-importing.