9421: XML parsing: illegal xml character
SQL ServerWhat does it mean?
SQL Server encountered a disallowed (invalid) character while parsing text as XML. The conversion to the XML type or the assignment to an XML column/variable failed because of this character.
Why does it happen?
Control characters forbidden in XML 1.0 (e.g. some characters in the 0x00-0x1F range), wrong encoding (encoding mismatch), or corrupt/unsanitized data from another source. Usually appears during CAST(... AS XML) or an INSERT into an XML column.
How to fix it
Strip invalid characters from the text before converting it to XML. Make the source encoding (UTF-8/UTF-16) compatible with the target; declare the correct encoding in the XML declaration. Remove control characters with REPLACE/NCHAR, or generate and validate the XML with a standard library in the application layer. If you must store the raw text, consider NVARCHAR(MAX).
More from this engine
- 3729Cannot DROP because it is being referenced by object
- 3961Snapshot isolation transaction failed because the object was modified by a DDL statement
- 1785Introducing FOREIGN KEY constraint may cause cycles or multiple cascade paths
- 15151Cannot find the object/principal because it does not exist or you do not have permission
- 4834You do not have permission to use the bulk load statement
- 10928Resource limit for the database has been reached (Azure SQL)
- 40544The database has reached its size quota (Azure SQL)