I am trying to modify a connectionString in an RDL file, which consists of xml nodes dynamically. but I am only able to retrieve the root using an / I cant retrieve any other nodes for example when I try to retrieve the connectString it comes up as null.

XmlDocument xml = new XmlDocument();
xml.Load(selectedFiles[0].ToString());
var connectionString = xml.SelectSingleNode("/"); 

the xml for the RDL file:

<?xml version="1.0" encoding="utf-8"?>
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition">
  <AutoRefresh>0</AutoRefresh>
  <DataSources>
    <DataSource Name="DataSource1">
      <ConnectionProperties>
        <DataProvider>SQL</DataProvider>
        <ConnectString>Data Source=gbr-t-sql-001;Initial Catalog=Neptune2Dev</ConnectString>
        <IntegratedSecurity>true</IntegratedSecurity>
      </ConnectionProperties>
      <rd:SecurityType>Integrated</rd:SecurityType>
      <rd:DataSourceID>70fcaa8f-d76a-4919-a53c-ba313ca99926</rd:DataSourceID>
    </DataSource>
  </DataSources>
  <DataSets>
    <DataSet Name="DataSet1">
      <Query>
        <DataSourceName>DataSource1</DataSourceName>
        <QueryParameters>
          <QueryParameter Name="@profileID">
            <Value>=Parameters!profileID.Value</Value>
          </QueryParameter>
        </QueryParameters>
        <CommandType>StoredProcedure</CommandType>
        <CommandText>Report_BylineSummary</CommandText>
有帮助吗?

解决方案

You need to execute an Xpath query to get the connection string. It should be something like this:

/Report/DataSources[@Name="DataSource1"]/ConnectionProperties/ConnectString

But taking care of correctly handling namespaces.

See this article:

http://www.codeproject.com/Articles/9494/Manipulate-XML-data-with-XPath-and-XmlDocument-C

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top