0

What is the most efficient way to create an XmlDataSource from an XmlReader? I'm trying to read an XML column from my MS-SQL database using the reader to prevent costy serialization of the data.

Here's my current code which doesn't seem to be really efficient:

Public Shared Function HoleDatenquelle(ByVal ConnectionString As String) As XmlDataSource
    Using con As New SqlConnection(ConnectionString)
        con.Open()

        Using XmlDataSource As New XmlDataSource()
            With XmlDataSource
                Using Reader = New SqlCommand("SELECT Daten FROM tblEinstellungen WHERE Benutzer = '_System_' AND Einstellung = 'Navigation'", con).ExecuteXmlReader()
                    .Data = Reader.ReadOuterXml()
                End Using
                .ID = DateTime.Now.Ticks.ToString()
                .XPath = "/Menü/*"
            End With
            Return XmlDataSource
        End Using
    End Using
End Function

Thanks in Advance!

André R.
  • 427
  • 7
  • 17
  • what's the actual problem ?? does this code caught error(s) or you need alternative methods to do this same job ?? – Vivek S. Jul 28 '14 at 10:35
  • looks sufficient to me.. I would do `Using Reader As System.Xml.XmlReader = ...` though – Brett Caswell Jul 28 '14 at 10:54
  • @dude The code works quite fine. My question is, if there is a more efficient way to achieve the task. Right now I'm serializing the XML file _Reader.ReadOuterXml()_ and I'm pretty sure that it's getting deserialized again inside the _XmlDatSource.Data_ property. – André R. Jul 28 '14 at 11:08

0 Answers0