Troubleshooting Guide: SQL Server Error 2269
Why This Error Happens
Error 2269 (“%sEnd tag ‘/%ls’ has no matching begin tag”) occurs when SQL Server’s XML parser encounters malformed XML data that violates well-formedness rules, typically during XML data type operations, FOR XML queries, or SSIS package processing. This is most commonly caused by corrupted XML source files, truncated data streams, or application code that manually concatenates XML strings without proper tag closure. It can also surface after an in-place upgrade to SQL Server 2025 if legacy stored procedures generate XML using string-building logic incompatible with stricter parser validation.
Step-by-Step Resolution Guide
Step 1: Identify the Source of the Malformed XML
- Check SQL Server error logs at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOGto capture the full stack trace and identify the offending query or job. - Run
SELECT * FROM sys.dm_exec_requests WHERE sql_handle IS NOT NULLto trace the exact statement executing at the time of failure. - If triggered by SSIS, open the package in SQL Server Data Tools and check the Data Flow task consuming the XML source.
Step 2: Validate and Repair the XML Payload
- Extract the raw XML string into a text editor or use
SELECT CAST(YourXmlColumn AS NVARCHAR(MAX))to inspect it manually. - Look for unclosed tags, mismatched case sensitivity (XML is case-sensitive), or improperly escaped special characters like
&,<, or>. - Use an online or local XML validator (e.g.,
xmllint --noout file.xmlvia Windows Subsystem for Linux) to pinpoint the exact line/column of the broken tag.
Step 3: Correct Application or Procedure Logic
- Review any stored procedures or application code using
FOR XML PATHor manual string concatenation (+ '</Tag>') to build XML. - Replace manual string-building with native XML data type methods such as
.query(),.value(), orFOR XML RAW/AUTOwith properTYPEdirectives to ensure well-formed output. - Rebuild and redeploy the corrected stored procedure or SSIS package.
Step 4: Clear Corrupted Cached Plans (If Applicable)
- Run
DBCC FREEPROCCACHEto eliminate any cached execution plans that may be referencing the faulty XML generation logic. - Restart the SQL Server service via
services.mscornet stop MSSQLSERVER && net start MSSQLSERVERon Windows Server 2025 to ensure a clean state.
Alternative or Verification Steps
- Re-run the original query or SSIS package and confirm Error 2269 no longer appears in
sys.dm_os_ring_buffersor the SQL Server error log. - If the issue persists, isolate the problem by testing with a minimal, hard-coded valid XML sample (
<Root><Child>Test</Child></Root>) to confirm the parser itself is functioning correctly, then incrementally reintroduce your original data structure to isolate the corrupt segment.