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

Troubleshooting Guide: SQL Server Error 6800 — FOR XML AUTO Requires a Table

Why This Error Happens

Error 6800 occurs when a SELECT ... FOR XML AUTO query is executed without a valid FROM clause referencing at least one table or view. The FOR XML AUTO mode relies entirely on the schema and hierarchy of source tables to automatically generate nested XML tags, so it cannot construct output from literals, variables, or expressions alone. This typically happens due to a malformed query, a dynamically generated SQL string missing the FROM clause, or a developer mistakenly porting a FOR XML RAW query structure into AUTO mode without including the required table reference.

Step-by-Step Resolution Guide

Step 1: Review the Query Syntax in SQL Server Management Studio (SSMS)

  • Open the failing query in SSMS 21 (compatible with SQL Server 2025) on your Windows Server 2025 or Windows 11 machine.
  • Check that the SELECT statement includes a valid FROM TableName or FROM ViewName clause before the FOR XML AUTO keyword.
  • Example of a broken query: SELECT 1 AS ID, 'Test' AS Name FOR XML AUTO; — this has no table reference and will always fail.

Step 2: Add a Valid Table Reference or Switch to FOR XML RAW

  • If the query logically requires pulling from a table, rewrite it as: SELECT ID, Name FROM dbo.Customers FOR XML AUTO;
  • If no table is actually needed (e.g., you are generating static or literal XML), switch the mode to RAW instead: SELECT 1 AS ID, 'Test' AS Name FOR XML RAW;
  • Confirm the table name is correctly schema-qualified (e.g., dbo.TableName) to avoid ambiguity errors in multi-schema databases.

Step 3: Inspect Dynamic SQL or Application Code

  • If the query is generated by an application (e.g., via Entity Framework, a stored procedure, or a reporting tool), check the code that builds the SQL string dynamically.
  • Search for any string concatenation logic where the FROM clause might be conditionally omitted based on a parameter value.
  • Add a validation check in the application layer to ensure the FROM clause is never stripped out before the query is sent to SQL Server 2025.

Step 4: Test the Corrected Query in Isolation

  • Run the corrected query directly in SSMS or Azure Data Studio against a test database to confirm it executes without Error 6800.
  • Check the Messages tab for confirmation that XML output was generated successfully instead of an error.

Alternative or Verification Steps

  • Verify the fix by executing the corrected query and confirming valid XML is returned in the Results grid (click the resulting link to view the full XML output).
  • If FOR XML AUTO continues to behave unexpectedly even with a table present, use FOR XML PATH('') as an alternative, which offers more explicit control over XML structure and does not have the same table-dependency restriction.