Troubleshooting Guide: TDS RPC Error 8002 (Invalid XML Database or Schema)
Why This Error Happens
This error occurs when a client application sends an RPC call containing an XML-typed parameter that references a database or schema collection that SQL Server 2025 cannot resolve in the current connection context. Typically, this happens because the XML schema collection was defined in a different database than the one the session is currently using, the schema collection name is misspelled or was dropped, or the client-side driver (ODBC/OLE DB/ADO.NET) is sending malformed metadata for the XML parameter. It can also surface after an in-place upgrade to SQL Server 2025 if legacy TDS client libraries are not fully compatible with updated XML type-handling in the RPC stream.
Step-by-Step Resolution Guide
Step 1: Verify the XML Schema Collection Exists and Is Scoped Correctly
- Run
SELECT * FROM sys.xml_schema_collections;in the target database to confirm the schema collection referenced by the parameter actually exists. - Confirm you are querying the correct database context — XML schema collections are database-scoped, not server-scoped, so a collection in
DB_Awill not resolve if the session context isDB_B. - Check the three-part naming convention in the client call (e.g.,
dbo.MySchemaCollection) and ensure the schema owner matches.
Step 2: Inspect and Correct the Client Connection String / Context
- Ensure the client application explicitly sets the correct
Initial Catalog(database) in the connection string before issuing RPC calls with XML parameters. - For applications using
USE [DatabaseName];statements dynamically, confirm this executes successfully before the XML parameter is bound. - If using ADO.NET, verify the
SqlParameterfor the XML type explicitly specifiesSqlDbType.Xmland does not pass an unqualified or null schema collection name.
Step 3: Update SQL Server Client Drivers and Native Client Libraries
- On Windows Server 2025 / Windows 11, update to the latest Microsoft OLE DB Driver or ODBC Driver for SQL Server, as older TDS libraries may mishandle XML type metadata introduced in SQL Server 2025.
- Navigate to
Control Panel > Programs > Programs and Featuresto check installed driver versions, or run:
Get-OdbcDriver | Where-Object {$_.Name -like "*SQL Server*"}
- Reinstall or patch the driver via the Microsoft Download Center if version mismatches are found.
Step 4: Rebuild or Re-register the XML Schema Collection
- If the schema collection appears corrupted or was partially migrated during an upgrade, drop and recreate it:
DROP XML SCHEMA COLLECTION dbo.MySchemaCollection;
CREATE XML SCHEMA COLLECTION dbo.MySchemaCollection AS N'<schema XML definition here>';
- Re-grant necessary permissions using
GRANT REFERENCES ON XML SCHEMA COLLECTION::dbo.MySchemaCollection TO [UserOrRole];.
Alternative or Verification Steps
- Use SQL Server Profiler or Extended Events to capture the exact RPC call and confirm the parameter now resolves to a valid, existing schema collection in the correct database context.
- If the error persists, bypass typed XML schema validation temporarily by casting the parameter to untyped XML (
XMLwithout a schema collection) to confirm whether the schema binding itself is the root cause.