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

Troubleshooting Guide: SQL Server Error 2219 — “There is no attribute named ‘@%ls’ in the type ‘%ls'”

Why This Error Happens

This error occurs when SQL Server parses XML data (typically during XML schema collection validation, FOR XML queries, or OPENXML operations) and encounters an attribute reference that does not exist in the defined XML schema type. The most common root cause is a mismatch between the XML schema collection registered in the database and the actual XML document structure being inserted or queried, often resulting from an incomplete schema migration or a manually edited XML instance. This can also surface after an in-place upgrade to SQL Server 2025 if legacy XML schema collections were not revalidated against the new XML parser engine.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Query and Schema Collection

  • Capture the exact query or stored procedure from SQL Server Error Logs or Extended Events (xml_deadlock_report won’t help here — instead filter for sql_statement_completed with error number 2219).
  • Run the following to identify associated XML schema collections in the database:
  SELECT name, xml_collection_id FROM sys.xml_schema_collections;
  • Note the specific attribute name (@%ls) and type (%ls) referenced in the error message text.

Step 2: Validate the XML Instance Against the Registered Schema

  • Extract the XML schema collection definition using:
  SELECT xml_schema_namespace('dbo', 'YourSchemaCollectionName');
  • Compare the attribute names in the extracted XSD against the attribute used in your XML payload — check for case sensitivity mismatches (ID vs Id) and namespace prefix errors.
  • If the application layer generates the XML, inspect the C#/Java/XML serialization code for recent changes to DTOs or POJOs that may have added new attributes not reflected in the SQL Server schema.

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

  • If the schema is outdated, alter it to include the missing attribute:
  ALTER XML SCHEMA COLLECTION dbo.YourSchemaCollectionName ADD '<xsd:schema>...</xsd:schema>';
  • Alternatively, drop and recreate the schema collection if ALTER is not supported for the specific structural change (attribute removal is not allowed via ALTER):
  DROP XML SCHEMA COLLECTION dbo.YourSchemaCollectionName;
  CREATE XML SCHEMA COLLECTION dbo.YourSchemaCollectionName AS N'<xsd:schema>...</xsd:schema>';
  • Restart the SQL Server service via services.msc or Restart-Service MSSQLSERVER in PowerShell (run as Administrator) on Windows Server 2025 to clear any cached execution plans referencing the old schema.

Step 4: Clear Cached Execution Plans

  • Flush the plan cache to ensure SQL Server 2025 does not reuse a stale execution plan built against the old schema definition:
  DBCC FREEPROCCACHE;
  • If running in a production environment, scope this to the specific database instead of the full instance:
  ALTER DATABASE SCOPED CONFIGURATION CLEAR PROCEDURE_CACHE;

Alternative or Verification Steps

  • Re-run the original INSERT, FOR XML, or OPENXML query that triggered Error 2219 and confirm successful execution with no attribute-related exceptions in sys.dm_exec_requests.
  • If the error persists after schema correction, use SQL Server Profiler or Extended Events on Windows Server 2025 to trace the exact XML payload being submitted at runtime, as the issue may originate from a client-side serialization bug rather than the server-side schema itself.