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

Troubleshooting Guide: SQL Server Error 2331 – “Redefinition has to have itself as base type”

Why This Error Happens

This error occurs when SQL Server’s XML schema collection processing encounters a type redefinition that does not properly reference itself as the base type, violating XSD (XML Schema Definition) redefinition rules. It is typically triggered by corrupted or manually edited XML schema collections, incompatible schema imports from legacy applications, or inconsistencies introduced during an in-place upgrade to SQL Server 2025. In some cases, third-party ORM tools or CLR assemblies that generate dynamic XML schemas can also produce malformed <xs:redefine> blocks that fail validation.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Schema Collection

  • Run the following query to locate schema collections that may be causing validation failures:
  SELECT name, schema_collection_id, xml_schema_namespace 
  FROM sys.xml_schema_collections;
  • Cross-reference the Location path reported in the error message (%ls) with the namespace returned above.
  • Check SQL Server Error Logs at C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG for the full stack trace and timestamp correlation.

Step 2: Validate and Correct the XML Schema Definition

  • Export the schema collection using SQL Server Management Studio (SSMS) 2025 by right-clicking the collection under Databases > Security > XML Schema Collections.
  • Open the exported .xsd file in a validator (such as Visual Studio 2025’s XML Schema Explorer) and manually inspect every <xs:redefine> element.
  • Ensure the redefined complex type explicitly extends or restricts itself, for example:
  <xs:redefine schemaLocation="original.xsd">
    <xs:complexType name="CustomerType">
      <xs:complexContent>
        <xs:extension base="CustomerType">
          <!-- new fields -->
        </xs:extension>
      </xs:complexContent>
    </xs:complexType>
  </xs:redefine>
  • Remove or fix any redefinition where the base type does not match the type being redefined.

Step 3: Drop and Recreate the Schema Collection

  • Drop the corrupted schema collection:
  DROP XML SCHEMA COLLECTION dbo.YourSchemaCollectionName;
  • Recreate it using the corrected .xsd file:
  CREATE XML SCHEMA COLLECTION dbo.YourSchemaCollectionName AS 
  'C:\SQLSchemas\corrected_schema.xsd';
  • If the schema is tied to a column or parameter definition, re-link it to the affected table or stored procedure after recreation.

Step 4: Clear Cached Compiled Schema Objects

  • Restart the SQL Server service to flush any cached, invalid schema compilation artifacts:
  Restart-Service -Name "MSSQLSERVER" -Force
  • On Windows Server 2025/Windows 11, confirm the service restarted cleanly via Services.msc or Event Viewer under Applications and Services Logs > MSSQLSERVER.

Alternative or Verification Steps

  • Re-run the original DDL statement or application query that triggered Error 2331 and confirm it completes without exception.
  • If the issue persists, use DBCC CHECKDB on the affected database to rule out underlying page-level corruption that may be affecting system metadata tables storing the schema collections.