I am trying to create an XElement of a datasource to insert into an SSRS RDL file. However, I am unable to seem to get it to create correctly with respect to the rd: alias. Here is the code I am using.
XNamespace rootNs = "http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition";
XNamespace rdNs = "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner";
XElement _dataSource = new XElement("DataSource",
new XAttribute(XNamespace.Xmlns + "rd", rdNs),
new XAttribute("Name", "eFinancials_LOCAL"),
new XElement("ConnectionProperties", new XElement("DataProvider", "SQL"), new XElement("ConnectString", connectionString)),
new XElement(_rdns + "SecurityType", "DataBase"),
new XElement(_rdns + "DataSourceID", dataSourceId)
);
Resulting XML element is:
<DataSource xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" Name="eFinancials_LOCAL">
<ConnectionProperties>
<DataProvider>SQL</DataProvider>
<ConnectString>Data Source=.;Initial Catalog=800_LMS_eFin_Deploy</ConnectString>
</ConnectionProperties>
<SecurityType xmlns="rd">DataBase</SecurityType>
<DataSourceID xmlns="rd">56e5e869-6ca5-44f9-8340-22821177569e</DataSourceID>
</DataSource>
But, it needs to be:
<DataSource Name="eFinancials_LOCAL">
<ConnectionProperties>
<DataProvider>SQL</DataProvider>
<ConnectString>Data Source=.;Initial Catalog=800_LMS_eFin_Deploy</ConnectString>
</ConnectionProperties>
<rd:SecurityType>DataBase</SecurityType>
<rd:DataSourceID>56e5e869-6ca5-44f9-8340-22821177569e</DataSourceID>
</DataSource>
How can I adjust my code to create the correct XML as above? I almost to the point where I am just going to create it as text.