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

Troubleshooting Guide: SQL Server Error 6352 – “Invalid Parameter Specified. XML Schema Collections Can Only Be Created From a String Literal”

Why This Error Happens

This error occurs when a CREATE XML SCHEMA COLLECTION statement attempts to reference a variable, column, or expression instead of a hardcoded string literal for the schema definition. SQL Server 2025 strictly enforces this requirement because the schema parser needs to validate and compile the XSD content at statement-creation time, not at runtime. This commonly happens when developers migrate dynamic SQL scripts or ORM-generated code that passes schema content through parameters rather than inline text.

Step-by-Step Resolution Guide

Step 1: Identify the Offending T-SQL Statement

  • Open SQL Server Management Studio (SSMS) or Azure Data Studio connected to your Windows Server 2025 instance.
  • Search recent scripts or deployment logs for CREATE XML SCHEMA COLLECTION statements.
  • Check if the schema source is passed as @variable or N'' + column_name instead of a direct literal string.

Step 2: Rewrite the Statement Using a String Literal

  • Replace any variable reference with the actual XSD content wrapped in single quotes, e.g.:
  CREATE XML SCHEMA COLLECTION MySchemaCollection AS
  N'<?xml version="1.0"?><xs:schema>...</xs:schema>';
  • If the schema is large, store it in a .sql file and use SSMS’s “Open File” feature to paste the raw literal directly into the script rather than loading it via a parameter.
  • Avoid EXEC sp_executesql with parameterized XSD content — this is the primary trigger for Error 6352.

Step 3: Fix Dynamic SQL or Application Code (If Applicable)

  • If the schema is generated by an application (e.g., .NET, Python, or PowerShell scripts connecting to SQL Server 2025), modify the code to inline the XSD text directly into the SQL command string before execution.
  • For PowerShell deployment scripts, verify that Invoke-Sqlcmd is not passing the schema as a -Variable substitution; instead, concatenate it directly into the -Query string.
  • Re-run the corrected script in SSMS to confirm the CREATE XML SCHEMA COLLECTION command executes without raising Error 6352.

Step 4: Clear and Reload the Schema Collection Cache

  • If the schema collection previously failed mid-creation, drop any partial objects:
  DROP XML SCHEMA COLLECTION MySchemaCollection;
  • Re-execute the corrected literal-based script to recreate the collection cleanly.

Alternative or Verification Steps

  • Verify the fix by querying sys.xml_schema_collections to confirm the new schema collection exists and has the expected xml_collection_id.
  • If the error persists despite using a literal, check for invisible Unicode characters or encoding mismatches (UTF-8 vs UTF-16) in the XSD string by re-saving the script file with “SQL Server Compatible” encoding in SSMS before re-running it.