如何动态修改RDl文件中的连接字符串
本文关键字:文件 连接 字符串 RDl 修改 何动态 动态 | 更新日期: 2023-09-27 18:12:41
我试图修改RDL文件中的connectionString,该文件由xml节点动态组成。但我只能使用/
检索根,我不能检索任何其他节点,例如,当我试图检索connectString时,它出现为空。
XmlDocument xml = new XmlDocument();
xml.Load(selectedFiles[0].ToString());
var connectionString = xml.SelectSingleNode("/");
RDL文件的xml:
<?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>
需要执行Xpath查询来获取连接字符串。应该是这样的:
/报告/数据源[@ name = " DataSource1 "]/ConnectionProperties ConnectString
但是要注意正确处理名称空间。
查看本文:
http://www.codeproject.com/Articles/9494/Manipulate-XML-data-with-XPath-and-XmlDocument-C