XML data source RRS feed

  • Question

  • Hi!

         I would like to use a xml file as a data source's configuration file: the user should change the data of Data Source and initial catalog values on it, and then I would take those values and use them to creat the connect string. But I don't want to publish this xml file. Is there anyway I can read from a xml file, not using http://server/file???


                   Thank you! 

    Thursday, June 8, 2006 5:59 PM


  • There are a couple of ways to accomplish this without publishing the xml file.

    1. You can use custom code to get the file from where it is located (the example below uses the file system) and parse it for the values you require, and then expose these values through a couple of properties. Here is an example,

    Add the following code to the Code section of the Report. In the Report Designer this is accomplished on the Code tab of the Report properties dialog.

    Private m_initialCatalog As String
    Private m_dataSource As String

    Public ReadOnly Property InitialCatalog As String
            Return m_initialCatalog
        End Get
    End Property

    Public ReadOnly Property DataSource As String
            Return m_dataSource       
        End Get
    End Property

    Protected Overrides Sub OnInit()
        ' Error handling ommitted for brevity

        Dim xmlDoc as New System.Xml.XmlDocument()

        m_initialCatalog = xmlDoc.SelectSingleNode("Config/InitialCatalog").InnerText
        m_dataSource = xmlDoc.SelectSingleNode("Config/DataSource").InnerText

    End Sub

    And change your connection string to use an expression. For example,

    ="Data Source=" & Code.DataSource & ";Initial Catalog=" & Code.InitialCatalog

    Note: To use the Xml related classes you need to add the System.Xml Assembly to the Code Modules section of the Report. In the Report Designer this is done on the References tab of the Report properties dialog.

    2. Another way is to not use an intermediary xml file and use Report Parameters, which are referenced in an expression in the Connection String field. The usefulness of this depends on the frequency of the user changing the connection string values, however.

    Thursday, June 8, 2006 9:31 PM