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

Troubleshooting Guide: SQL Server Error 6937 – XML Canonical Form Validation Failure

Why This Error Happens

Error 6937 occurs when SQL Server’s XML parser attempts to validate a typed XML value against an XML Schema Collection (XSD) and finds that the value’s canonical representation does not conform to the restrictions defined in the schema. This typically results from applying pattern facets (regex-like restrictions) to non-string data types, using range restrictions on floating-point values (which can have multiple valid lexical representations for the same value, such as “1.0” vs “1.0E0”), or from a corrupted/malformed XML Schema Collection registered in the database. It can also surface after an in-place upgrade to SQL Server 2025 if legacy XSD collections used constructs that are now more strictly validated by the updated XML engine.

Step-by-Step Resolution Guide

Step 1: Identify the Offending XML Schema Collection and Column

  • Run the following query to locate XML columns bound to schema collections in the affected database:
  • SELECT c.name AS ColumnName, t.name AS TableName, xsc.name AS SchemaCollectionName FROM sys.columns c JOIN sys.tables t ON c.object_id = t.object_id JOIN sys.xml_schema_collections xsc ON c.xml_collection_id = xsc.xml_collection_id;
  • Note the exact schema collection name and the table/column throwing the error during INSERT or UPDATE operations.
  • Reproduce the error on a single row in a test environment to isolate the exact value causing the canonical form mismatch.

Step 2: Extract and Inspect the XSD for Problematic Facets

  • Extract the current schema definition using: SELECT xml_schema_namespace('dbo', 'YourSchemaCollectionName');
  • Search the output for <xs:pattern> elements applied to xs:decimal, xs:float, or xs:double types—these are common triggers for 6937.
  • Check for <xs:minInclusive> or <xs:maxInclusive> restrictions combined with enumerations on floating-point types, as SQL Server 2025 enforces stricter W3C canonical form compliance than previous versions.
  • Flag any float/double fields using scientific notation inconsistently (e.g., mixing “1E2” and “100” in the same dataset).

Step 3: Correct the Schema or Normalize the Data

  • If the pattern facet is unnecessary on a numeric type, remove it and rely on xs:minInclusive/xs:maxInclusive alone for range enforcement.
  • If the data itself is non-canonical (e.g., “+1.50” instead of “1.5”), normalize the XML data at the application layer or via a CONVERT/CAST pass before insertion using: SELECT CAST(CAST(YourXmlColumn AS NVARCHAR(MAX)) AS XML).query('.') to force re-validation.
  • Drop and recreate the XML Schema Collection with the corrected XSD: ALTER XML SCHEMA COLLECTION dbo.YourSchemaCollectionName ADD '<xs:schema>...</xs:schema>';
  • Restart the SQL Server service via services.msc or Restart-Service MSSQLSERVER in PowerShell (run as Administrator) if schema cache issues persist after the ALTER.

Step 4: Clear Cached Query Plans Referencing the Old Schema

  • Run DBCC FREEPROCCACHE; to ensure no stale execution plans reference the outdated schema collection metadata.
  • If using a named instance, target it specifically: DBCC FREEPROCCACHE WITH NO_INFOMSGS;
  • Re-run the original INSERT/UPDATE statement that triggered Error 6937 to confirm resolution.

Alternative or Verification Steps

  • Verify the fix by inserting a known-good XML sample containing edge-case floating-point values (e.g., “0.0”, “1E10”, “-0.001”) and confirming no 6937 error is raised.
  • If the error persists, bypass strict typed XML validation temporarily by casting the column to untyped XML (without schema binding) to confirm the schema—not the underlying SQL Server installation—is the root cause, then rebuild the XSD from scratch using W3C-compliant canonical examples.