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

Why This Error Happens

Error 6962 occurs when SQL Server attempts to register or validate an XML Schema Collection (XSD) that contains a restricted element type (such as elements typed as xs:ID, xs:IDREF, or certain complex content types) with a default or fixed attribute value assigned. The SQL Server XML parser strictly enforces W3C XML Schema constraints, and per W3C specification, elements derived from these specific types are prohibited from carrying default or fixed constraints because it creates ambiguous validation states. This typically surfaces when importing third-party XSDs, migrating schema collections from older SQL Server versions (2019/2022) to SQL Server 2025, or when a schema file has been manually edited and corrupted.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Schema Element

  • Run the failing CREATE XML SCHEMA COLLECTION or ALTER XML SCHEMA COLLECTION statement and capture the full error text; the %s placeholder will usually resolve to the specific element name (e.g., elementName).
  • Open the source .xsd file in a text editor or Visual Studio 2022/2025 XML editor and search for that element name using Ctrl+F.
  • Check if the element’s type attribute is set to xs:ID, xs:IDREF, xs:IDREFS, or a complex type derived by restriction/extension from one of these.

Step 2: Remove or Relocate the Default/Fixed Constraint

  • Delete the default="value" or fixed="value" attribute directly from the offending <xs:element> or <xs:attribute> tag.
  • If the constraint logic is required by your application, move the default-value handling into application-layer code (e.g., C#/.NET data layer) rather than the schema definition.
  • Save the corrected XSD file to a known path, such as C:\SQLSchemas\corrected_schema.xsd.

Step 3: Re-import the Corrected Schema Collection

  • Open SQL Server Management Studio (SSMS 21) connected to your SQL Server 2025 instance.
  • Drop the old faulty collection if it partially exists: DROP XML SCHEMA COLLECTION dbo.MySchemaCollection;
  • Import the fixed file using:
    CREATE XML SCHEMA COLLECTION dbo.MySchemaCollection AS N'<paste corrected XSD content here>';
  • Alternatively, load it via PowerShell using Invoke-Sqlcmd -InputFile "C:\SQLSchemas\corrected_schema.xsd" if scripting the deployment.

Step 4: Validate Permissions and Compatibility Level

  • Confirm the database compatibility level supports the schema features in use: SELECT compatibility_level FROM sys.databases WHERE name = 'YourDB'; (should be 170 or higher for SQL Server 2025 features).
  • Ensure the executing login has ALTER permission on the XML Schema Collection or db_ddladmin role membership, as insufficient permissions can sometimes mask as malformed registration errors in chained scripts.

Alternative or Verification Steps

  • Verify the fix: Query sys.xml_schema_collections to confirm the collection registered successfully, then run a test INSERT against a table using that XML column/type to ensure validation passes without Error 6962.
  • Alternative: If the XSD originates from a vendor and cannot be edited, use an XSLT transformation step to strip default/fixed attributes programmatically before passing the content to the CREATE XML SCHEMA COLLECTION command.