Why This Error Happens
This error occurs when SQL Server 2025 attempts to parse an XML Schema Collection (XSD) that defines a complex type derived from anyType using extension, a pattern the SQL Server XML engine does not support. It typically surfaces during schema registration (CREATE XML SCHEMA COLLECTION) or when importing third-party WSDL/XSD definitions that were authored for a general-purpose XML parser rather than SQL Server’s restricted XSD subset. The underlying cause is almost always a schema file containing unsupported constructs rather than a server configuration or permissions issue.
Step-by-Step Resolution Guide
Step 1: Identify the Offending Schema File
- Locate the exact
.xsdor WSDL file referenced in the failingCREATE XML SCHEMA COLLECTIONorALTER XML SCHEMA COLLECTIONstatement. - Search the file for
<xs:extension base="xs:anyType">or<xs:extension base="anyType">declarations. - Check SQL Server error logs at
C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOGfor the full stack trace pointing to the schema import statement.
Step 2: Modify the Schema to Avoid anyType Extension
- Replace
<xs:extension base="xs:anyType">with a restriction against a concrete named complex type instead ofanyType. - If the schema is auto-generated (e.g., from a WCF or WSDL export tool), regenerate it using a profile that targets “SQL Server compatible XSD” if the tool supports it.
- Manually flatten the type hierarchy so the derived type explicitly lists all inherited elements rather than extending
anyType.
Step 3: Re-import the Corrected Schema Collection
- Open SQL Server Management Studio (SSMS) 21 connected to your Windows Server 2025 instance.
- Run the corrected script:
CREATE XML SCHEMA COLLECTION dbo.FixedSchemaCollection
AS N'<the corrected XSD content>';
- If the collection already exists, drop it first with
DROP XML SCHEMA COLLECTION dbo.OldSchemaCollection;before re-creating it.
Step 4: Validate XML Columns Bound to the Schema
- If any table column uses
XML (CONTENT dbo.FixedSchemaCollection), re-run a validation query:
SELECT * FROM sys.xml_schema_collections WHERE name = 'FixedSchemaCollection';
- Confirm the column constraint binds successfully without throwing Error 2237 on insert/update operations.
Alternative or Verification Steps
- Verify the fix by re-running the original
CREATE XML SCHEMA COLLECTIONstatement in a test database and confirming it completes without Error 2237, then insert a sample XML document that conforms to the new schema to confirm validation passes. - If modifying the XSD is not feasible (e.g., third-party vendor schema), consider storing the XML as untyped
XMLdatatype without schema validation, and enforce structure checks at the application layer instead.