I just defined a RDL Report that has a connection to a shared DataSource(*.rds file). I want to copy the file in the App_Data directory, eand change the connection when I am in the Test environment and when I am in the Production environment. | You can modify/edit the report datasource or other section of report by accessing the report definition. You have to serialize the report and modify the desired property of the report definition, modified report definition need to be saved in to stream or file, before loading the report to ReportWriter/ReportViewer. We have prepared a sample to modify the ReportDefinition dynamically and It can be downloaded from the following location. http://www.syncfusion.com/downloads/support/forum/119473/ModifyDatasourceReference1670620741.zip | |
There is a way to specify this other than the DataSourceCredentials? | If we modify the datasource reference, then we have to provide the credential of the modify datasource as shown by below code snippet,
|
So there is not a way to use a Shared Data Source that can be updated once when I put the application in production. | We could not modify the shared datasource used in report dynamically. If you need to modify shared datasource dynamically, then you have to edit the report definition. |
There is a way to pass to the ReportViewer the stream of the reportdefinition transformed or have I to write back a phisical file everytime I load a report. In that case the best solution will be a procedure to change the reports one time when I publish them, but is risky if I forget a single one. I was hoping in anything automatic to use. | we have already exposed a Stream property in ReportViewerModel to load modified report stream in ReportViewer. Using this property, you can load modified report stream without saving into physical file, but we have some issues while assigning the report steam property and we have logged issue report on this. A support incident to track the status of this defect has been created under your account. Please log on to our support website to check for further updates https://www.syncfusion.com/account/login?ReturnUrl=%2fsupport%2fdirecttrac%2fincidents |
my question regarding the shared datasource is not how to change it, but how to use it when the report is not published in Report Server and loaded in the App_Data directory. I have copied the file .rds in the same directory, but when I try to load the report in the reportviewer, there is an error in the rendering that says that cannot find datasource. If it is possible to use it, could you provide me a working example? | We could not read the shared datasource information from local physical location through ReportViewer control, but we can able to read shared datasource from App_Data location and assign the shared datasource information to report datasource while loading the report. We have prepared sample based on this and it can be downloaded from below location, http://www.syncfusion.com/downloads/support/forum/119473/ReportViewerDemo-1111710594.zip |
public void OnInitReportOptions(ReportViewerOptions reportOption) { reportOption.ReportModel.Stream = this.SerializeReport(reportOption.ReportModel.ReportPath); reportOption.ReportModel.ReportPath = null; } private Stream SerializeReport(string path) { Syncfusion.RDL.DOM.ReportDefinition reportDefinition = new Syncfusion.RDL.DOM.ReportDefinition(); FileInfo info = new FileInfo(path); FileStream stream = new FileStream(info.FullName, FileMode.Open, FileAccess.Read, FileShare.Read); XElement rdl = XElement.Load(XmlReader.Create(stream)); string Namespace = (from attribute in rdl.Attributes() where attribute.Name.LocalName == "xmlns" select attribute.Value).FirstOrDefault(); string Version = (Regex.IsMatch(Namespace, @"\d{4}") ? Regex.Match(Namespace, @"\d{4}").Value : string.Empty); XmlSerializer xs = new XmlSerializer(typeof(Syncfusion.RDL.DOM.ReportDefinition), Namespace); stream.Position = 0; stream.Close(); using (StringReader reader = new StringReader(rdl.ToString())) { reportDefinition = (Syncfusion.RDL.DOM.ReportDefinition)xs.Deserialize(reader); } foreach (var datasource in reportDefinition.DataSources) { XmlDataDocument xmldoc = new XmlDataDocument(); FileStream _dsStream = new FileStream(new FileInfo(HttpContext.Current.Server.MapPath("~/App_Data/AdventureWorksAS2008R2.rds")).FullName, FileMode.Open, FileAccess.Read, FileShare.Read); xmldoc.Load(_dsStream); XmlNode _node = xmldoc.FirstChild.NextSibling; //Here you can edit the connection properties of the DataSource. if (!string.IsNullOrEmpty(datasource.DataSourceReference)) { } } stream.Close(); return this.SaveReport(reportDefinition); } |