Three steps as boxes: prepare returns a handle, OPENXML reads two rows through it, and release makes the handle unusable with message 8179, plus notes that the handle outlives the batch and that CATCH releases it

sp_xml_preparedocument: Prepare XML in Memory and Always Release It

sp_xml_preparedocument parses an XML document into memory and returns a handle that OPENXML can read. This post shows the safe pattern with TRY and CATCH, why the handle number is not yours to choose, what happens when you reuse a released handle, and how the WITH clause and flags shape the rows. Every result comes from SQL Server 2025.

Read More