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

Why This Error Happens

Error 2382 occurs when SQL Server 2025 attempts to parse or register an XML Schema Collection (XSD) that contains a logically invalid particle declaration, specifically where the minOccurs value is greater than the maxOccurs value, or where maxOccurs is set to a non-positive integer incorrectly. This typically happens when a schema file has been manually edited, corrupted during a migration, or generated by a third-party tool that does not strictly adhere to W3C XSD validation rules. Because SQL Server’s native XML parser enforces strict compliance, it rejects the schema binary entirely rather than attempting a partial import.

Step-by-Step Resolution Guide

Step 1: Isolate the Offending Schema Collection

  • Open SQL Server Management Studio (SSMS) and connect to the instance throwing the error.
  • Run SELECT name, xml_schema_namespace FROM sys.xml_schema_collections; to identify the specific collection being loaded or altered when the error triggers.
  • Export the XSD using SELECT CONVERT(xml, xml_schema_namespace) FROM sys.xml_schema_collections WHERE name = 'YourSchemaName'; to inspect the raw text.

Step 2: Validate the XSD Structure Manually

  • Copy the exported schema definition into a local .xsd file on your Windows Server 2025 or Windows 11 machine (e.g., C:\Temp\schema_validation\broken_schema.xsd).
  • Search the file for the attributes minOccurs and maxOccurs. Look specifically for instances where minOccurs="2" is paired with maxOccurs="1", or where maxOccurs="0" is used without minOccurs="0".
  • Correct the logic so that maxOccurs is always greater than or equal to minOccurs, or set maxOccurs="unbounded" if the field repetition count is not fixed.

Step 3: Re-Register the Corrected Schema

  • Drop the broken collection using DROP XML SCHEMA COLLECTION YourSchemaName; (ensure no active tables are strictly bound to it, or use ALTER instead if constraints exist).
  • Re-import the fixed file using a command prompt or SSMS query: CREATE XML SCHEMA COLLECTION YourSchemaName AS 'C:\Temp\schema_validation\fixed_schema.xsd';
  • Restart the “SQL Server (MSSQLSERVER)” service via services.msc on Windows Server 2025 to clear any cached execution plans referencing the old, corrupted schema structure.

Step 4: Check Application-Side Serialization Libraries

  • If the schema is generated dynamically by a .NET application (common in Windows 11 dev environments), verify the version of System.Xml.Schema being used.
  • Ensure the application code explicitly defines Occurs properties rather than relying on default serialization behaviors which can sometimes generate conflicting values during complex type inheritance.

Alternative or Verification Steps

  • To verify the fix, run a test INSERT or UPDATE statement against a table that uses the XML datatype bound to this schema; if the data passes validation without throwing Error 2382, the structure is confirmed fixed.
  • If the error persists after manual editing, use the XML Schema Explorer in Visual Studio 2025 to visually validate the “Compositor” properties of the schema, as this tool often catches nested sequence/choice conflicts that a simple text search might miss.