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

Why This Error Happens

This error occurs when SQL Server attempts to register or alter an XML Schema Collection where a derived complex type uses xs:anyAttribute or xs:any wildcards that are broader or incompatible with the wildcard defined in its base type. Per W3C XML Schema validation rules, a restricting type’s wildcard (including its namespace and processContents attributes) must be a proper subset of the base type’s wildcard—SQL Server’s internal XSD parser strictly enforces this during schema collection creation. This typically stems from a malformed or manually edited XSD file, a third-party schema import that wasn’t validated against W3C constraints, or an application generating schemas programmatically without proper inheritance checks.

Step-by-Step Resolution Guide

Step 1: Identify the Offending XML Schema Collection

  • Run the following query to locate recently modified or problematic schema collections:
  SELECT name, xml_schema_namespace, create_date, modify_date 
  FROM sys.xml_schema_collections 
  ORDER BY modify_date DESC;
  • Extract the full schema definition for inspection:
  SELECT xml_schema_namespace(N'dbo', N'YourSchemaCollectionName');
  • Note the specific complex type referenced in the error message (%s).

Step 2: Validate the XSD Against W3C Wildcard Restriction Rules

  • Open the extracted schema in an XML editor (Visual Studio, Oxygen XML, or VS Code with XML extension).
  • Locate the <xs:complexType> definition using <xs:restriction base="..."> and check its <xs:anyAttribute namespace="..."> declaration.
  • Confirm the namespace attribute value (e.g., ##any, ##other, or a list of URIs) in the derived type is equal to or narrower than the base type’s wildcard—never broader.
  • Verify processContents (e.g., strict, lax, skip) in the derived type is equally or more restrictive than the base type’s setting.

Step 3: Correct the Schema Definition

  • Edit the XSD file to narrow the namespace attribute on the restricted type’s wildcard so it falls within the base type’s allowed namespace set.
  • If the base type uses namespace="##other", ensure the derived type does not use namespace="##any".
  • Save the corrected XSD file locally (e.g., C:\SQLSchemas\corrected_schema.xsd).

Step 4: Re-register the Schema Collection

  • Drop the old faulty collection (if it exists and is not in use):
  DROP XML SCHEMA COLLECTION dbo.YourSchemaCollectionName;
  • Re-create it using the corrected file:
  CREATE XML SCHEMA COLLECTION dbo.YourSchemaCollectionName
  AS N'<paste corrected XSD content here>';
  • Check the SQL Server error log (via SSMS > Management > SQL Server Logs, or C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG on Windows Server 2025) to confirm no residual Error 6994 entries appear.

Step 5: Update Dependent Application Code

  • If the schema is generated dynamically by an application (e.g., via XSD.exe, a .NET XmlSchema object, or an ORM), update the code generation logic to enforce W3C wildcard subset rules before submission to SQL Server.
  • Re-deploy and re-test the application’s XML insert/validation workflow.

Alternative or Verification Steps

  • Verify the fix by inserting a test XML document that exercises the previously failing complex type: SELECT CAST('<test>...</test>' AS XML) validated against the new schema collection — it should succeed without error.
  • If re-authoring the XSD is not feasible, as a workaround, remove the <xs:restriction> inheritance chain and flatten the complex type definition (duplicating the base type’s wildcard rules directly) to avoid the restriction validation entirely.