Troubleshooting Guide: SQL Server Error 6905 – XML Validation Attribute Error
Why This Error Happens
Error 6905 occurs when SQL Server’s XML schema validation engine encounters an attribute in an XML instance document that is not defined or permitted by the associated XML Schema Collection (XSCHEMA). This typically happens due to a mismatch between the XML data being inserted/validated and the schema definition, often caused by an outdated or incorrectly versioned XSD schema bound to the column. It can also result from application-side XML generation changes that were not synchronized with the database schema collection, or from a corrupted schema collection object within the database.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Attribute and Schema Collection
- Run the failing query/statement again and capture the full error message, noting the specific attribute name (%s) referenced in the error.
- Query the schema collection associated with the target XML column using:
SELECT xsc.name, xs.*
FROM sys.xml_schema_collections xsc
CROSS APPLY sys.xml_schema_namespaces xs
WHERE xsc.xml_collection_id = (SELECT xml_collection_id FROM sys.columns WHERE name = 'YourXMLColumn');
- Compare the attribute causing the error against the registered schema to confirm the mismatch.
Step 2: Update or Re-register the XML Schema Collection
- If the schema is outdated, alter it using
ALTER XML SCHEMA COLLECTIONto add the missing attribute definition, or drop and recreate it if structural changes are required. - Example for adding to an existing collection:
ALTER XML SCHEMA COLLECTION dbo.YourSchemaCollection
ADD '<xs:schema>...updated definition...</xs:schema>';
- Ensure the new XSD file path (if loading from disk on Windows Server 2025, e.g.,
C:\SQLSchemas\updated_schema.xsd) is accessible by the SQL Server service account.
Step 3: Validate Application XML Output
- On the application server (Windows 11/Windows Server 2025), check the XML generation logic (e.g., in .NET, Java, or middleware) to ensure it is not injecting deprecated or extra attributes not covered by the current schema version.
- Update the application’s XML serializer or mapping configuration to align with the current XSD.
Step 4: Rebuild Corrupted Schema Collections (If Applicable)
- If the schema collection object itself is suspected to be corrupted, drop it and reload it cleanly:
DROP XML SCHEMA COLLECTION dbo.YourSchemaCollection;
- Reload using
CREATE XML SCHEMA COLLECTIONwith a verified, clean XSD file to eliminate any internal metadata corruption.
Alternative or Verification Steps
- After applying the fix, re-run the original INSERT/UPDATE statement or application transaction that triggered Error 6905 to confirm the XML now validates successfully against the schema collection.
- As an alternative, if frequent schema mismatches occur, consider relaxing validation by using an untyped
XMLcolumn instead of a typed one bound to a schema collection, provided business logic allows for looser validation constraints.