Troubleshooting Guide: SQL Server Error 7005 — “OPENXML requires a metaproperty namespace…”
Why This Error Happens
This error occurs when a query uses sp_xml_preparedocument or OPENXML with the namespace prefix mp explicitly declared for a different URI, while SQL Server internally reserves mp for its own metaproperty namespace (urn:schemas-microsoft-com:xml-metaprop). This creates a namespace collision, since SQL Server cannot distinguish between your custom-declared mp prefix and the one it needs internally to process metaproperties like @mp:id or @mp:parentid. The conflict is purely a T-SQL query design issue rather than a server configuration or permissions problem, meaning it will occur consistently regardless of the Windows Server 2025 or Windows 11 host environment.
Step-by-Step Resolution Guide
Step 1: Identify the Conflicting Namespace Declaration
- Open the stored procedure, function, or ad-hoc script that calls
sp_xml_preparedocument. - Search for any
WITH XMLNAMESPACESclause or inline XML namespace declaration that definesmpas a prefix (e.g.,xmlns:mp="http://your-custom-uri"). - Confirm this is the source by temporarily commenting out the
OPENXMLcall and running the XML parsing portion alone.
Step 2: Rename the Conflicting Prefix
- Change your custom namespace prefix from
mpto a non-reserved alias, such ascmporcustns. - Update every reference throughout the query, for example:
WITH XMLNAMESPACES ('http://your-custom-uri' AS cmp)- Update XPath references like
@cmp:idinstead of@mp:id - Save the script and re-run it in SSMS (SQL Server Management Studio) connected to your SQL Server 2025 instance.
Step 3: Explicitly Declare the Metaproperty Namespace (If Required)
- If your query intentionally needs both custom metadata and SQL Server’s metaproperties, declare the
mpnamespace explicitly at the top of your query: WITH XMLNAMESPACES ('urn:schemas-microsoft-com:xml-metaprop' AS mp, 'http://your-custom-uri' AS cmp)- Ensure the metaproperty namespace URI is typed exactly as shown — any typo will cause OPENXML to fail silently or throw a different parsing error.
Step 4: Clean Up XML Handles
- Add
EXEC sp_xml_removedocument @hdoc;after everyOPENXMLoperation to prevent memory leaks and handle conflicts on subsequent calls. - Verify no orphaned XML document handles exist by restarting the SQL Server service on Windows Server 2025 if the issue persists across multiple sessions:
- Open Services.msc → locate SQL Server (MSSQLSERVER) → Restart
Alternative or Verification Steps
- Re-run the corrected query in SSMS and confirm Error 7005 no longer appears in the Messages tab; check the SQL Server Error Log (via
EXEC sp_readerrorlog;) to confirm no residual namespace warnings. - As an alternative, migrate the query logic to use
XMLdata type methods (.nodes(),.value()) instead ofOPENXML, as this modern approach avoids manual namespace/prefix management entirely.