July 21, 2004 at 12:05 pm
According to BOL, the return value of sp_xml_removedocument is 0 for success and >1 for failure.
I tried on three different servers, it always returns 1.
Can anyone try the following test?
DECLARE @hdoc int
DECLARE @Rtn int
DECLARE @doc nvarchar(1000)
SELECT @hdoc=0,@Rtn=-1
SET @doc =N'
<ROOT>
<Customer CustomerID="VINET" ContactName="Paul Henriot">
<Order CustomerID="VINET" EmployeeID="5" OrderDate="1996-07-04T00:00:00">
<OrderDetail OrderID="10248" ProductID="11" Quantity="12"/>
<OrderDetail OrderID="10248" ProductID="42" Quantity="10"/>
</Order>
</Customer>
<Customer CustomerID="LILAS" ContactName="Carlos Gonzlez">
<Order CustomerID="LILAS" EmployeeID="3" OrderDate="1996-08-16T00:00:00">
<OrderDetail OrderID="10283" ProductID="72" Quantity="3"/>
</Order>
</Customer>
</ROOT>'
--Create an internal representation of the XML document.
EXEC @Rtn=sp_xml_preparedocument @hdoc OUTPUT, @doc
IF @@ERROR=0
BEGIN
PRINT 'The return value for sp_xml_preparedocument is '+CAST(@Rtn as nvarchar(50))+N'. The handle is '+CAST(@hdoc as nvarchar(50))
END
DECLARE @Dummy nvarchar(20)
SELECT @Dummy = CustomerID
FROM OPENXML (@hdoc, '/ROOT/Customer',1)
WITH (CustomerID nvarchar(10),
ContactName nvarchar(20))
-- Remove the internal representation.
SET @Rtn=-1
exec @Rtn=sp_xml_removedocument @hdoc
IF @@ERROR=0
BEGIN
PRINT 'The return value for sp_xml_removedocument is '+CAST(@Rtn as nvarchar(50))
END
July 22, 2004 at 1:52 am
Tried it with the same result - also tried on some code we've been using loads (with no problems, fingers crossed ) and that returns a 1 as well.
Found this link on google groups
which indicates this is a bug and it always returns 1.
I tried putting in a duff handle to remove and you do seem to be able to check @@ERROR to see if it fails though.
jt
July 22, 2004 at 6:59 am
Thanks for your input. It seems it's a MS bug. Just check @@Error should workaround. Thanks again.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply