Troubleshooting Guide: SQL Server Error 9463 – XML Parsing Failure
Why This Error Happens
Error 9463 occurs when SQL Server’s internal XML parser encounters malformed, incomplete, or improperly encoded XML data at a specific line number within a column, variable, or stored procedure input. This is typically caused by corrupted XML data being inserted into an xml-typed column, mismatched or unclosed tags, invalid character encoding (such as non-UTF-8 byte sequences), or truncation of the XML string due to a datatype length mismatch (e.g., casting to varchar instead of nvarchar(max)). It can also surface after an in-place upgrade to SQL Server 2025 if legacy XML schema collections were not validated against the newer parser engine.
Step-by-Step Resolution Guide
Step 1: Isolate the Offending XML Data
- Identify the exact line and column number referenced in the error message (e.g., “line 4, character 12”).
- Run a validation query against the source table:
SELECT TRY_CAST(XmlColumn AS XML) FROM YourTable WHERE TRY_CAST(XmlColumn AS XML) IS NULL AND XmlColumn IS NOT NULL; - Export the problematic row’s raw data to a text file to inspect for unclosed tags or invalid characters.
Step 2: Correct Data Type and Encoding Issues
- Verify the source application is not casting XML data as
varcharwhen it should benvarchar(max), which causes silent truncation of Unicode characters. - Check connection string encoding settings in your application (ensure
CollationandCharsetmatch UTF-8/UTF-16 as required). - In SQL Server Management Studio (SSMS) 21, open Tools > Options > Query Execution and confirm “SET XML Datatype Compatibility” settings align with 2025 defaults.
Step 3: Repair or Re-import the XML Schema Collection
- If the error originates from a typed XML column bound to an XML Schema Collection, run:
SELECT xsc.name, xs.definition FROM sys.xml_schema_collections xsc CROSS APPLY sys.xml_schema_namespaces xs WHERE xsc.xml_collection_id = xs.xml_collection_id; - Drop and recreate the schema collection using
CREATE XML SCHEMA COLLECTIONwith a verified, well-formed.xsdfile. - Restart the SQL Server service via
services.mscorRestart-Service MSSQLSERVERin PowerShell (run as Administrator) to clear cached execution plans referencing the old schema.
Step 4: Validate Application-Side XML Generation
- On Windows Server 2025/Windows 11, check the Event Viewer (
eventvwr.msc) under Applications and Services Logs > Microsoft > SQL Server for correlating client-side serialization errors. - Ensure any .NET application generating the XML uses
XmlWriterwith explicit encoding (Encoding.UTF8) rather than manual string concatenation.
Alternative or Verification Steps
- Re-run the original query or stored procedure that triggered Error 9463; confirm it completes without exception and returns expected row counts.
- If the issue persists, use
DBCC CHECKDBon the affected database to rule out underlying page-level corruption masquerading as an XML parsing failure.