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

Troubleshooting Guide: SQL Server Error 2391 – “Redefining XSD Schemas is Not Supported”

Why This Error Happens

This error occurs when a CREATE XML SCHEMA COLLECTION or ALTER XML SCHEMA COLLECTION statement attempts to add a schema component (such as a complex type, element, or attribute) that already exists within the target namespace of an existing XML Schema Collection. SQL Server 2025 enforces strict immutability on XSD definitions once they are registered, meaning you cannot silently overwrite or redefine a type that was previously committed to the collection. This typically happens during application deployment scripts or ORM migrations where a schema is pushed multiple times without first checking for existing definitions or properly versioning the namespace.

Step-by-Step Resolution Guide

Step 1: Identify the Conflicting Schema Collection

  • Open SQL Server Management Studio (SSMS) and connect to the instance running on Windows Server 2025.
  • Run the following query to locate the specific collection causing the conflict:
  SELECT xsc.name, xsc.xml_collection_id, s.name AS schema_owner
  FROM sys.xml_schema_collections xsc
  JOIN sys.schemas s ON xsc.schema_id = s.schema_id;
  • Note the xml_collection_id and the specific namespace mentioned in the Error 2391 message detail.

Step 2: Drop and Recreate the Schema Collection (Rather Than Redefining)

  • Since “Redefining” is unsupported, you must explicitly drop the old definition before pushing the new one.
  • Use the following syntax to safely remove the old schema before your deployment script runs:
  IF EXISTS (SELECT * FROM sys.xml_schema_collections WHERE name = 'YourSchemaName')
  DROP XML SCHEMA COLLECTION YourSchemaName;
  • Re-run your original CREATE XML SCHEMA COLLECTION script immediately after the drop completes.

Step 3: Update Deployment Scripts to Use ALTER Correctly

  • If you are trying to add new types to an existing collection (rather than changing existing ones), ensure you are using ALTER XML SCHEMA COLLECTION ADD with net-new, non-conflicting namespace components.
  • Check your CI/CD pipeline (e.g., Azure DevOps or GitHub Actions) configuration files located in your deployment repository to ensure the schema migration step includes a “drop-if-exists” check rather than a direct “create” command on every run.

Step 4: Check for Dependent Objects

  • Before dropping the schema collection in Step 2, verify no existing tables or XML-typed columns are bound to it, as this will throw a dependency error.
  • Run sp_depends 'YourSchemaName' or query sys.xml_schema_collections dependencies to identify and temporarily unbind affected columns if necessary.

Alternative or Verification Steps

  • Verification: Re-run the deployment script a second time to confirm the CREATE XML SCHEMA COLLECTION command completes without throwing Error 2391, confirming the drop/recreate cycle is working.
  • Alternative: If dropping the schema is not feasible due to production dependencies, create a new schema collection with a versioned name (e.g., MySchema_v2) and update the application’s table definitions to point to the new collection instead of overwriting the old one.