Troubleshooting Guide: SQL Server Error 9430 — “XML Parsing: Line %d”
Why This Error Happens
Error 9430 occurs when SQL Server’s internal XML parser encounters malformed, incomplete, or improperly encoded XML data being inserted into an xml data type column or passed to an XML-handling function. This is typically caused by invalid characters, unclosed tags, mismatched namespaces, or truncated XML content arriving from an application, import file, or linked server query. It can also surface due to corrupted data pages or a mismatch between the XML schema collection and the actual document structure in Microsoft SQL Server 2025 running on Windows Server 2025 / Windows 11.
Step-by-Step Resolution Guide
Step 1: Isolate the Offending XML Data
- Identify the exact line number referenced in the error message (
line %d) to narrow down the malformed section. - Run the failing query in SQL Server Management Studio (SSMS) with
SET SHOWPLAN_XML OFFand capture the raw input usingPRINTorSELECT @xmlVariablebefore the parsing step. - Use
SELECT CAST(@xmlData AS XML)in isolation to confirm whether the error reproduces outside the larger batch.
Step 2: Validate and Repair the XML Source
- Open the source file or payload in a text editor (e.g., VS Code on Windows 11) and check for unclosed tags, invalid entity references (like unescaped
&,<,>), or BOM/encoding issues (UTF-8 vs UTF-16 mismatches). - Validate the document against any associated XML Schema Collection using:
SELECT xml_schema_namespace('dbo', 'YourSchemaCollectionName');
- If the data originates from an external application or ETL job, check the source system logs under
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\for truncation or encoding errors during transmission.
Step 3: Correct Application-Side Encoding and Escaping
- Ensure the client application properly escapes special characters before sending XML (e.g., using
System.Xml.XmlWriterin .NET rather than manual string concatenation). - Confirm the connection string specifies the correct character encoding (
Charset=utf-8) to prevent mid-stream corruption. - Re-run the insert/update operation after correcting the payload to confirm the parser no longer throws Error 9430.
Step 4: Check for Database-Level Corruption
- Run
DBCC CHECKDB('YourDatabaseName') WITH NO_INFOMSGS, ALL_ERRORMSGS;to rule out page-level corruption affecting XML column storage. - Review the SQL Server Error Log (via SSMS > Management > SQL Server Logs) for correlating I/O or storage engine warnings around the same timestamp as the 9430 error.
Alternative or Verification Steps
- Verify the fix by re-executing the original INSERT/UPDATE statement or ETL job and confirming no Error 9430 appears in the SQL Server Error Log or Windows Event Viewer (Event ID source: MSSQLSERVER).
- If the issue persists, bypass strict schema validation temporarily by casting to untyped
XML(without a schema collection) to confirm whether the schema collection itself — rather than the raw document — is the root cause.