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

Troubleshooting Guide: Error 6903 – XML Schema Collection ID Attribute Validation Failure

Why This Error Happens

This error occurs when registering an XML Schema Collection in SQL Server 2025 that contains an attribute or element defined with the xs:ID type, which SQL Server’s XML validation engine explicitly does not support. SQL Server’s internal XML schema processor restricts certain W3C XML Schema constructs—including ID, IDREF, and IDREFS—because it cannot guarantee uniqueness constraints across document instances the way a native XML parser would. This is almost always a schema design issue introduced during migration, import, or third-party schema generation rather than a server configuration or permissions problem.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Schema Component

  • Capture the full error message, which includes the type name in %ls (e.g., Invalid definition for type 'EmployeeRecordType').
  • Open the .xsd file or extract the schema using:
  SELECT xml_schema_namespace('YourSchema', 'YourCollectionName');
  • Search the output for attributes or elements declared with type="xs:ID", type="xs:IDREF", or type="xs:IDREFS".

Step 2: Modify the XML Schema Definition

  • Replace any xs:ID typed attribute with xs:string or xs:token instead, since SQL Server cannot enforce ID uniqueness natively.
  • Example fix:
  <!-- Unsupported -->
  <xs:attribute name="RecordID" type="xs:ID"/>

  <!-- Supported -->
  <xs:attribute name="RecordID" type="xs:string"/>
  • If uniqueness enforcement is required, implement it at the application layer or via a CHECK constraint/trigger after shredding the XML into relational columns.

Step 3: Drop and Re-Create the XML Schema Collection

  • Remove the old collection (ensure no columns/tables reference it first):
  DROP XML SCHEMA COLLECTION YourSchema.YourCollectionName;
  • Re-register the corrected schema:
  CREATE XML SCHEMA COLLECTION YourSchema.YourCollectionName AS N'<your corrected XSD content here>';
  • If the collection is referenced by existing typed XML columns, you will need to temporarily convert those columns to untyped XML, drop the collection, recreate it, then reapply the typed binding.

Step 4: Validate Dependent Objects

  • Check for stored procedures, functions, or table definitions that reference the schema collection using:
  SELECT * FROM sys.xml_schema_collections WHERE name = 'YourCollectionName';
  • Recompile any dependent objects with sp_refreshsqlmodule to ensure they pick up the corrected schema binding.

Alternative or Verification Steps

  • Verify the fix: Re-run the original CREATE XML SCHEMA COLLECTION or ALTER statement that triggered Error 6903 — it should now complete without error, and you can confirm registration via SELECT name FROM sys.xml_schema_collections;.
  • Alternative workaround: If modifying the source XSD isn’t feasible (e.g., third-party generated schema), strip the xs:ID constraint programmatically using an XSLT transformation before importing the schema into SQL Server, preserving the field as a plain string type.