B
Brett Robichaud
I am trying to get data as XML from my SQL 2k server.
My select statement is:
SELECT TOP 10 * FROM IMAGE FOR XML AUTO, ELEMENTS
I then use this code to wrtie it to a file:
XmlWriter w = new XmlTextWriter(@"foo.xml", Encoding.UTF8);
w.WriteStartDocument();
w.WriteStartElement("Test");
rdr.MoveToContent();
while (rdr.Read())
w.WriteNode(rdr, false);
w.WriteEndElement();
w.WriteEndDocument();
w.Close();
I am consistently getting this exception. It seems like the xml is garbled.
Any ideas?
System.InvalidOperationException: Token StartElement in state Epilog would
result in an invalid XML document.
at System.Xml.XmlTextWriter.AutoComplete(Token token)
at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String
localName, String ns)
at System.Xml.XmlWriter.WriteNode(XmlReader reader, Boolean defattr)
at MyImageBridge.Data.DBLayerApp.XmlGetSpiderData(String sCustID,
DateTime dtFrom, DateTime dtTo) in
c:\dev\ice\apps\web\corporate\myimagebridge\codebehind\dblayerapp.cs:line
371
My select statement is:
SELECT TOP 10 * FROM IMAGE FOR XML AUTO, ELEMENTS
I then use this code to wrtie it to a file:
XmlWriter w = new XmlTextWriter(@"foo.xml", Encoding.UTF8);
w.WriteStartDocument();
w.WriteStartElement("Test");
rdr.MoveToContent();
while (rdr.Read())
w.WriteNode(rdr, false);
w.WriteEndElement();
w.WriteEndDocument();
w.Close();
I am consistently getting this exception. It seems like the xml is garbled.
Any ideas?
System.InvalidOperationException: Token StartElement in state Epilog would
result in an invalid XML document.
at System.Xml.XmlTextWriter.AutoComplete(Token token)
at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String
localName, String ns)
at System.Xml.XmlWriter.WriteNode(XmlReader reader, Boolean defattr)
at MyImageBridge.Data.DBLayerApp.XmlGetSpiderData(String sCustID,
DateTime dtFrom, DateTime dtTo) in
c:\dev\ice\apps\web\corporate\myimagebridge\codebehind\dblayerapp.cs:line
371