1

I have some RDL reports created with SQL Server BI Development Studio and now I need to render them using the ASP.NET Report Viewer. Even though my RDLs contain references to the SQL server and the SELECT query, it keeps saying I need to specify a datasource for the report. Is there a way to make the datasource from the RDL be used or do I have to pass a datasource to the report viewer via C# code?

Thank you.

Joao de Araujo
  • 1,096
  • 2
  • 15
  • 27

2 Answers2

5

I suppose you are using the Report Viewer in local mode:

viewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Local

and you use viewer.LocalReport. In this case you has to run query yourself and pass the result to the viewer:

dim tbl as new DataTable()

Fill the data e.g. tbl.load(datareader).

Dim VDS As New ReportDataSource
VDS.Name = "Your Data Source Name"
VDS.Value = tbl
viewer.LocalReport.DataSources.Add(VDS)

If you want to use server mode

viewer.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote

You has to use viewer.ServerReport

viewer.ServerReport.ReportServerUrl = New Uri(ReportServerURL)

and probably viewer.ServerReport.SetDataSourceCredentials

Reporting Services and ReportViewer Controls in Visual Studio

Edit
How to get queries from rdl
Initialization:

Dim XRep As New XmlDocument
XRep.Load(ReportPath)
Dim xmlnsManager As New System.Xml.XmlNamespaceManager(XRep.NameTable)
dim DefaultNSURI as string = XRep.GetElementsByTagName("Width")(0).NamespaceURI
xmlnsManager.AddNamespace("rep", DefaultNSURI)

Dataset Processing:

For Each nd As XmlNode In XRep.SelectNodes("/rep:Report/rep:DataSets/rep:DataSet", xmlnsManager)
   'DataSourceName can be used to find iformation about connection' 
   Dim DataSourceName As String = nd.SelectSingleNode("rep:Query/rep:DataSourceName", xmlnsManager).InnerText  
   Dim DSName As String = nd.Attributes("Name").Value       
   cmd.CommandText = nd.SelectSingleNode("rep:Query/rep:CommandText", xmlnsManager).InnerText
   Dim tbl As New DataTable(DSName)
   tbl.Load(cmd.ExecuteReader)
    'The table created here is to be passed to  LocalReport as datasource'
 Next

Note To convert vb.net<->c# I use Convert VB.NET to C#

IvanH
  • 5,039
  • 14
  • 60
  • 81
1

Did you verify the DataSourceReference element in your RDL? It needs the path to the reporting server.

The DataSourceReference element can contain a full folder path (for example, /SampleReports/AdventureWorks) or a relative path (for example, AdventureWorks). Relative paths start in the same folder as the report. The shared data source must be on the same server as the report.

Verify the DataSourceID too. Take a look at the answer on this question. It looks like it might be the same problem you are having.

If you are using an RDLC you could also set the datasource of your report manually using ReportDataSource. "GetMyData" in the example below would implement IEnumerable or IDataSource.

ReportDataSource reportDataSource = new ReportDataSource("MyDataName", GetMyData(startAt, endAt));
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Reporting/MyReport.rdlc");

ReportParameterCollection col = new ReportParameterCollection();
ReportParameter startAtParam = new ReportParameter("StartAt", startAt.ToString("MMM, dd yyyy"));
col.Add(startAtParam);
ReportParameter endAtParam = new ReportParameter("EndAt", endAt.ToString("MMM, dd yyyy"));
col.Add(endAtParam);

ReportViewer1.LocalReport.SetParameters(col);   

If you are converting an RDL to an RDLC you can follow the steps here. Note that you need to re-create data source and query information. Also, the XML schema definition is different between 2005 and 2008.

Community
  • 1
  • 1
  • I think I'm mixing things up here. I researched a bit more and found what I actually need is a RDLC, since I want to render the report definition using the Report Viewer without a report server involved. Still, I need to use my datasets and datasources from the RDL(C) file. Am I going the right direction? – Joao de Araujo Apr 09 '12 at 13:43
  • But isn't it possible to just convert a RDL to RDLC, keeping the dataset and datasource specifications that come from the RDL and use them without having to do all that declaration? I mean, if I already have a query and a path to a SQL Server specified there on the RDL, I wouldn't like to do it all again just because I'm not rendering that report at a server anymore. Hope I'm clear. – Joao de Araujo Apr 09 '12 at 14:28
  • What version of Visual Studio did you make the report in? Take a look at the 'How to Convert Report Definitions' steps [here](http://msdn.microsoft.com/en-us/library/ms252109(v=vs.90).aspx) – Paul Patterson Apr 09 '12 at 14:55