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

Troubleshooting Guide: SQL Server Error 2368

Why This Error Happens

Error 2368 occurs when SQL Server parses an XML Schema Collection (XSD) definition and encounters a type that has been declared with simple content (meaning it should only contain text or attribute values) but the schema also attempts to nest child elements inside it. This is typically caused by a malformed or manually edited XSD file, a corrupted schema collection in the database, or an application update that pushed an invalid XML configuration schema. It frequently surfaces during SSIS package execution, database schema imports, or when SQL Server attempts to validate XML data against a XML SCHEMA COLLECTION that violates W3C XML Schema structure rules.

Step-by-Step Resolution Guide

Step 1: Identify the Offending Schema Collection

  • Run the following query to locate the specific schema collection referenced in the error location path (%ls):
  • SELECT name, xml_schema_namespace, schema_collection_id FROM sys.xml_schema_collections WHERE name LIKE '%YourSchemaName%';
  • Cross-reference the Location string in the error message with the namespace URI returned to confirm which object is causing the conflict.
  • Check SQL Server Error Logs via C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG for the exact timestamp and triggering T-SQL statement.

Step 2: Extract and Validate the XSD Definition

  • Export the raw schema text using: SELECT xml_schema_namespace FROM sys.xml_schema_collections WHERE schema_collection_id = [ID_FROM_STEP_1];
  • Paste the output into a validator tool (such as Visual Studio’s XML Schema Explorer or an online XSD linter) to pinpoint the exact complexType tag causing the conflict.
  • Look specifically for a <xs:simpleContent> or <xs:restriction base="xs:string"> block that incorrectly contains nested <xs:element> tags—this structure is illegal per XML Schema specification and must be converted to <xs:complexContent> if child elements are required.

Step 3: Drop and Recreate the Corrected Schema Collection

  • Since ALTER XML SCHEMA COLLECTION only supports adding components (not fixing existing ones), you must drop the broken collection first: DROP XML SCHEMA COLLECTION [YourSchemaName];
  • Re-create it using the corrected XSD file: CREATE XML SCHEMA COLLECTION [YourSchemaName] AS 'C:\SchemaFiles\CorrectedSchema.xsd';
  • If the schema is tied to a third-party application (e.g., SSIS, BizTalk, or a vendor ERP), update the application’s configuration files to point to the patched schema version rather than editing the database object directly, in case the app overwrites it on restart.

Step 4: Restart the SQL Server Service and Clear Cache

  • Open Services.msc on Windows Server 2025 and restart the SQL Server (MSSQLSERVER) service to clear any cached execution plans referencing the old schema.
  • Alternatively, run DBCC FREEPROCCACHE; to avoid a full service restart if this is a production environment with high availability requirements.

Alternative or Verification Steps

  • Verify the Fix: Re-run the original query, SSIS package, or application process that triggered the error. Check sys.xml_schema_collections again to confirm the schema_collection_id is active and query XML_SCHEMA_NAMESPACE() function against a sample document to ensure it validates without throwing Error 2368.
  • Alternative Fix: If you cannot immediately edit the XSD source, temporarily cast the problematic column to untyped XML (removing the WITH XMLSCHEMA binding) to restore functionality while the schema file is corrected offline by the development team.