2017-02-02 2 views
0

XML로 데이터를 반환하는 저장 프로 시저가 있습니다. 원래 루트 노드는 테이블 이름 자체였습니다. 또한 루트 노드가 "xml"이되도록 변경했습니다. 저장 프로 시저XmlReader가 저장 프로 시저에서 Xml 결과를 읽지 않습니다.

:

string xmlresult = string.Empty; 

using (var command = (SqlCommand)connection.CreateCommand()) 
{ 
    command.CommandText = "sp_dosomething"; 
    command.CommandType = CommandType.StoredProcedure; 

    using (XmlReader reader = command.ExecuteXmlReader()) 
    { 
     while (reader.Read()) 
     { 
      xmlresult = reader.ReadOuterXml(); 
     } 
    } 
} 

예외이다 : ExecuteXmlReader 전송

잘못된 명령은 다음과 같은 결과를 판독 할 때

SELECT * FROM mytable 
FOR XML PATH('mytable'), ROOT('xml'), ELEMENTS; 

같은 문제가 발생한다. 이 명령은 Xml 결과를 반환해야합니다.

에서 : System.Data.SqlClient.SqlCommand.ExecuteXmlReader()

에서 System.Data.SqlClient.SqlCommand.CompleteXmlReader (SqlDataReader 개체 DS) 에서

나는 무엇이다 잘못하고있는거야?

+1

xml 및 저장 프로 시저를 제공하십시오. –

+0

@RonakPatel xml과 sp는 매우 복잡하지만 xml을 반환하는 방법을 추가 할 것입니다. –

+0

데모 xml을 제공해야하므로 도움을받을 수 있습니다. –

답변

1

오류로부터 당신이 얻는 것은 XML 결과가 아님이 분명합니다.

ExecuteXmlReader() 대신 ExecuteReader()을 사용하여 출력을 확인하십시오. 확실히 좋은 XML이 아닐 것입니다.

// execute the command 
reader = cmd.ExecuteReader(); 

// iterate through results, printing each to console 
while (reader.Read()) 
{ 
    Console.WriteLine("Print the data here and check output will not be XML in your case"); 
} 
+0

제안한대로했는데 예외는 다음과 같습니다 : 'System.Guid'유형의 객체를 'System .끈'. 참고 : XML의 몇 노드는'uniqueidentifier'입니다. 그것은 여전히 ​​전체 XML을 반환하지 않습니다. –

관련 문제