Ask a questionAsk a question
 

AnswerProblem with Execute XML Reader

  • Monday, November 02, 2009 12:57 PMShadaan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

     I have written a Stored Procedure in SQL Server 2008 which returns XML output using the FOR XML Clause in the Select statement. 
     When I execute the Stored Procedure from the DB Directly it gives me a perfect XML Output as desired. But when I am using it from my application it gives me an exception which says - "Invalid command sent to ExecuteXmlReader.  The command must return an Xml result."

    I have used this in several other places and its working fine. But not here. 
    Kindly help in this regard.

    Shadaan.

Answers

  • Monday, November 02, 2009 2:32 PMGanesh Ranganathan - Bangalore, India Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Did you check whether the query is returning the xml with the xml declaration statement and also the root node?

    Also you could a normal SqlDataReader instead of an XmlReader and retrieve. Since you are using the For XML keyword, it would always return valid xml.


    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net

All Replies

  • Monday, November 02, 2009 1:32 PMVic Vega Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Shadaan,
    Is it possible to put some code and stored procedure so that a solution can be provided ?

    Thanks
    PKR
  • Monday, November 02, 2009 2:32 PMGanesh Ranganathan - Bangalore, India Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Did you check whether the query is returning the xml with the xml declaration statement and also the root node?

    Also you could a normal SqlDataReader instead of an XmlReader and retrieve. Since you are using the For XML keyword, it would always return valid xml.


    Ganesh Ranganathan
    [Please mark the post as answer if it answers your question]
    blog.ganeshzone.net
  • Monday, November 09, 2009 7:02 AMeryangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi Shadaan,
    It is a long time since the last reply, did you get useful information from above suggestions, or you still have any concern about this issue? Please let us know.

    Thanks,

    Eric


    Please remember to mark helpful replies as answers and unmark them if they provide no help.