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
.xsdfile on your Windows Server 2025 or Windows 11 machine (e.g.,C:\Temp\schema_validation\broken_schema.xsd). - Search the file for the attributes
minOccursandmaxOccurs. Look specifically for instances whereminOccurs="2"is paired withmaxOccurs="1", or wheremaxOccurs="0"is used withoutminOccurs="0". - Correct the logic so that
maxOccursis always greater than or equal tominOccurs, or setmaxOccurs="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 useALTERinstead 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.mscon 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.Schemabeing used. - Ensure the application code explicitly defines
Occursproperties 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
INSERTorUPDATEstatement against a table that uses theXMLdatatype 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.