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

Troubleshooting Guide: SQL Server Error 2328 — Schema Namespace Mismatch

Why This Error Happens

Error 2328 occurs when SQL Server parses an XML document or schema collection and finds that the namespace declared in the document (or referenced via xmlns) does not match the target namespace defined in the associated XML Schema Collection (XSD). This typically results from a corrupted or outdated XML Schema Collection stored in the database, a mismatched namespace string due to manual editing, or an application sending XML data that references an incorrect or versioned schema URI. It can also surface after a schema collection migration or restore where the namespace binding became stale relative to the application’s directive.

Step-by-Step Resolution Guide

Step 1: Identify the Conflicting Schema Collection

  • Run the following query to locate the XML Schema Collection tied to the error:
  SELECT name, xml_schema_namespace, create_date, modify_date
  FROM sys.xml_schema_collections
  WHERE schema_id = SCHEMA_ID('dbo');
  • Cross-reference the xml_schema_namespace value with the namespace declared in the incoming XML document (check the xmlns attribute at the root element).
  • Review application logs or the SQL Server ERRORLOG at C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG for the full error context, including the two namespace strings reported.

Step 2: Correct the Namespace Mismatch

  • If the application-side XML namespace changed (e.g., versioned schema like http://schemas.company.com/orders/v2), update the XML payload to reference the namespace currently registered in SQL Server, or:
  • Drop and recreate the XML Schema Collection with the updated namespace:
  DROP XML SCHEMA COLLECTION dbo.OrderSchemaCollection;
  GO
  CREATE XML SCHEMA COLLECTION dbo.OrderSchemaCollection
  AS N'<xsd:schema targetNamespace="http://schemas.company.com/orders/v2" ...></xsd:schema>';
  GO
  • Ensure the targetNamespace attribute in the .xsd file matches exactly (case-sensitive) with what the application sends.

Step 3: Rebind Columns and Validate Dependent Objects

  • If any xml typed columns reference the schema collection, verify they aren’t locked to a stale version:
  SELECT c.name, t.name AS schema_collection
  FROM sys.columns c
  JOIN sys.xml_schema_collections t
  ON c.xml_collection_id = t.xml_collection_id;
  • Recompile stored procedures or functions that validate XML against this schema using sp_recompile.
  • Restart the SQL Server service via services.msc or:
  Restart-Service -Name 'MSSQLSERVER' -Force

Step 4: Re-test the XML Insert/Validation Operation

  • Re-run the original INSERT/UPDATE statement or application transaction that triggered Error 2328.
  • Confirm no namespace-related errors appear in SSMS or the application’s exception log.

Alternative or Verification Steps

  • Verify the fix by executing a test query that casts a sample XML document against the schema collection: SELECT CAST('<root xmlns="http://schemas.company.com/orders/v2">...</root>' AS XML) and confirm no errors are thrown.
  • If the mismatch persists, consider exporting the schema via sp_help_jobschedule-style scripting tools or SSMS “Generate Scripts” wizard to recreate the XML Schema Collection from a known-good source, ensuring namespace consistency across all environments (Dev/QA/Prod).