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

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

Why This Error Happens

Error 6938 occurs when SQL Server’s XML validation engine attempts to reconcile a value against an XML Schema Collection (XSD) that contains restrictive facets—such as pattern, enumeration, or range restrictions—applied to data types where they are not reliably supported, particularly floating-point types (float, double, decimal). Because the canonical (lexical) representation of floating-point numbers can vary (e.g., scientific notation, trailing zeros, precision rounding), the XML parser fails to match the stored value against the strict facet rule even though the underlying numeric value is technically correct. This is typically triggered by a malformed or overly strict XSD schema registered in the database, or by an application inserting XML data with a numeric format that doesn’t normalize cleanly under the W3C XML Schema canonicalization rules.

Step-by-Step Resolution Guide

Step 1: Identify the Offending XML Schema Collection

  • Run the following query to locate schema collections in the affected database:
  SELECT name, xml_collection_id FROM sys.xml_schema_collections;
  • Use SELECT XML_SCHEMA_NAMESPACE('schema_name', 'collection_name') to extract and inspect the raw XSD content.
  • Look specifically for <xs:restriction base="xs:float">, xs:double, or xs:decimal combined with <xs:pattern> or <xs:enumeration> facets.

Step 2: Correct or Relax the Schema Facets

  • Modify the XSD source to remove pattern/enumeration facets from floating-point base types; instead, validate ranges at the application layer or use xs:string with pattern validation if format enforcement is required.
  • Re-register the corrected schema using:
  ALTER XML SCHEMA COLLECTION [dbo].[YourCollectionName]
  ADD '<xsd corrected schema content here>';
  • If the collection cannot be altered due to dependencies, drop and recreate it:
  DROP XML SCHEMA COLLECTION [dbo].[YourCollectionName];
  CREATE XML SCHEMA COLLECTION [dbo].[YourCollectionName] AS N'<corrected XSD>';

Step 3: Normalize the Offending Data Value

  • Identify the exact row/value causing the failure by isolating the INSERT/UPDATE batch (binary search on batch size if bulk-loading).
  • Convert problematic floating-point values to a canonical string format before insertion (e.g., force two-decimal rounding or remove trailing zeros) using CONVERT(varchar, value, 2) or application-side formatting ("G17" format specifier in .NET is often incompatible—use "R" or explicit rounding instead).
  • Re-run the INSERT/UPDATE statement against the typed XML column to confirm the value now validates.

Step 4: Patch and Update SQL Server 2025

  • Check your current build with:
  SELECT @@VERSION;
  • Apply the latest Cumulative Update (CU) via Windows Update or the SQL Server Update Center, as XML canonicalization edge-case bugs for floating-point facets are frequently addressed in CUs.
  • Restart the SQL Server service (services.msc → SQL Server (MSSQLSERVER) → Restart) after patching.

Alternative or Verification Steps

  • Verify the fix by re-inserting the original failing dataset into the typed XML column and confirming no Error 6938 is raised in SQL Server Management Studio (SSMS) or the Application Event Log.
  • As a workaround if schema correction isn’t feasible immediately, change the target column to untyped xml (remove the WITH (XML_SCHEMA_COLLECTION) binding) temporarily to unblock data ingestion while the schema is redesigned.