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

Troubleshooting Guide: SQL Server Error 2220 — “There is no attribute named ‘@%ls:%ls'”

Why This Error Happens

This error occurs when SQL Server 2025 parses an XML document (typically during OPENXML, sp_xml_preparedocument, or XML schema validation operations) and encounters a reference to a namespace-qualified attribute that does not actually exist in the source XML. This is most commonly caused by a mismatch between the namespace prefix declared in the XML/XSD and the prefix actually used in XPath or attribute-mapping expressions within your T-SQL query or SSIS package. It can also surface when an application upgrade or a corrupted XML schema collection in the database silently altered namespace bindings, causing previously valid queries to break.

Step-by-Step Resolution Guide

Step 1: Identify the Offending XML Query or Schema

  • Capture the exact T-SQL statement, stored procedure, or SSIS Data Flow task throwing Error 2220 using SQL Server Profiler or Extended Events (filter on error_reported with Error = 2220).
  • Open the XML source document and locate the attribute referenced in the error message (replace %s and %ls placeholders with actual namespace/attribute names from the error text).
  • Confirm whether the query uses OPENXML, .value(), .nodes(), or .exist() XML data type methods.

Step 2: Validate Namespace Prefixes and Declarations

  • Compare the WITH XMLNAMESPACES clause (or xmlns: declarations in the source document) against the prefix used in your XPath expression — a single typo (e.g., ns1 vs ns:1) triggers this error.
  • Run the query in SQL Server Management Studio (SSMS) on Windows 11/Windows Server 2025 with the XML document pasted directly to isolate parser behavior:
  DECLARE @xml XML = '<root xmlns:ns="http://example.com">...</root>';
  SELECT @xml.value('(/root/@ns:attribute)[1]', 'nvarchar(100)');
  • Correct any mismatched namespace alias so it matches exactly, including case sensitivity.

Step 3: Rebuild or Re-register the XML Schema Collection

  • If the error originates from a registered XML Schema Collection, check its definition:
  SELECT name, xml_schema_namespace FROM sys.xml_schema_collections;
  • Drop and re-create the schema collection with the correct namespace definitions:
  DROP XML SCHEMA COLLECTION dbo.MySchemaCollection;
  CREATE XML SCHEMA COLLECTION dbo.MySchemaCollection AS N'<xsd:schema>...</xsd:schema>';
  • Restart the SQL Server service via Services.msc or net stop MSSQLSERVER && net start MSSQLSERVER to clear any cached execution plans referencing the old schema.

Step 4: Patch and Update SQL Server 2025

  • Apply the latest Cumulative Update (CU) for SQL Server 2025 via Windows Update or the Microsoft Update Catalog, since XML parser bug fixes are frequently bundled in CUs.
  • Verify the build number post-update:
  SELECT @@VERSION;
  • Reboot Windows Server 2025 / Windows 11 if the update requires a restart to fully register the patched XML parsing libraries.

Alternative or Verification Steps

  • Re-run the original failing query or SSIS package after each step; success is confirmed when the attribute resolves without Error 2220 and returns the expected value.
  • As an alternative, bypass strict namespace resolution by using a wildcard XPath (*:attribute) or sql:variable() function to dynamically bind namespace prefixes instead of hardcoding them.