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

Troubleshooting Guide: SQL Server Error 6935 – XML ID/IDREF Attribute Length Exceeded

Why This Error Happens

This error occurs when SQL Server’s XML parser validates an XML document against a schema (XSD) and encounters an attribute typed as ID or IDREF whose string value exceeds the internal maximum length limit imposed by the XML engine. This is typically triggered by malformed or auto-generated XML data (such as GUIDs or concatenated keys) being inserted into an xml-typed column that has an associated XML schema collection. It can also surface after upgrading to SQL Server 2025 on Windows Server 2025/Windows 11, where stricter XML validation parsing limits are enforced compared to legacy engine builds.

Step-by-Step Resolution Guide

Step 1: Identify the Offending XML Data and Column

  • Run SELECT name, xml_collection_id FROM sys.columns WHERE xml_collection_id <> 0; to locate all columns bound to an XML Schema Collection.
  • Use SELECT * FROM sys.xml_schema_collections; to identify which schema is enforcing the ID/IDREF constraint.
  • Export the problematic row’s XML data using SELECT CAST(YourXmlColumn AS NVARCHAR(MAX)) FROM YourTable WHERE PrimaryKey = X; to inspect the attribute values manually.

Step 2: Correct the XML Schema Collection Definition

  • Open the XSD source file (often stored in C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Schemas\ on Windows Server 2025).
  • Locate the attribute defined as xs:ID or xs:IDREF and check if it is unnecessarily strict; consider changing it to xs:string with a custom xs:maxLength restriction if business logic allows.
  • Re-register the schema in SQL Server using: ALTER XML SCHEMA COLLECTION dbo.YourSchemaCollection ADD 'file:///C:\Schemas\updated_schema.xsd';

Step 3: Truncate or Regenerate Oversized Identifier Values

  • If the ID is being auto-generated by an application (e.g., a GUID chain or hierarchical path key), modify the application logic to shorten the identifier before XML serialization.
  • For keys exceeding limits (the XML ID type caps at a finite NCName length), hash long values using HASHBYTES('SHA2_256', @LongID) and convert to a shorter hex string before insertion.

Step 4: Update SQL Server 2025 Cumulative Update

  • Open PowerShell as Administrator and check your current build: SELECT @@VERSION;
  • Navigate to the Microsoft Update Catalog and install the latest Cumulative Update (CU) for SQL Server 2025, as early builds had a known regression in MSXML6.dll interop validation length checks.
  • Restart the SQL Server service via services.msc or Restart-Service -Name 'MSSQLSERVER' in PowerShell.

Alternative or Verification Steps

  • Re-run the original INSERT or UPDATE statement that triggered Error 6935; if successful, query sys.dm_os_ring_buffers or the SQL Error Log (via EXEC sp_readerrorlog 0, 1, 'XML Validation') to confirm no recurrence.
  • As a workaround if schema modification isn’t feasible, strip the XML schema binding temporarily using ALTER TABLE YourTable ALTER COLUMN YourXmlColumn XML; (without DOCUMENT collection reference) to allow unvalidated inserts while you resolve the underlying data length issue.