This is a migrated thread and some comments may be shown as answers.

Loading reports dynamically from database to ReportViewer

6 Answers 378 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Oliver
Top achievements
Rank 1
Oliver asked on 05 Dec 2013, 03:46 AM
I have an WPF app with ReportViewer in one project and in another are all the telerik reports.
Via this app, I'll be calling the report selected in the dropdown to view.
Also I have the associated reports class name in the database.
I have the following snipet and it doesn't seem to work:

using (DBEntities db = new DBEntities(DBConnection.EntityModelConnectionString()))
{
   Report report = db.Reports.FirstOrDefault(r => r.ReportID == ReportID);

   Telerik.ReportViewer.Wpf.ReportViewer _reportViewer = new Telerik.ReportViewer.Wpf.ReportViewer();
   ReportViewerPlaceholder.Content = _reportViewer;
   _reportViewer.ReportSource = new Telerik.Reporting.TypeReportSource { TypeName = report.ClassName }
}

Am I missing something? An example will be great.

6 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 09 Dec 2013, 03:51 PM
Hi Oliver,

Please double check if the assembly qualified name of the report object can be resolved. We tested loading a report in a WPF ReportViewer as follows:
public partial class Window1 : Window
   {
       public Window1()
       {
           InitializeComponent();
           var viewer = new Telerik.ReportViewer.Wpf.ReportViewer();
           this.Content = viewer;
           viewer.ReportSource = new TypeReportSource { TypeName = "Telerik.Reporting.Examples.CSharp.BarcodesReport, CSharp.ReportLibrary" };
         }
 }
The result is successfully displaying the specified report.

If you need further help, please specify the result at your side, including the full stack trace of any received exceptions. Feel free to open a support ticket and send us a sample project illustrating the problem, that we can run and test.

Regards,
Stef
Telerik

New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

0
Oliver
Top achievements
Rank 1
answered on 10 Dec 2013, 01:56 AM
Hi Stef,

I've used the code snipet below and I'm getting this error:

"an error has occurred while processing the report"

I understand it will use the connectionstring in app.config. What if I want to change the connectionstring to
a log in one instead of using what is in app.config. Also will that propagate to subreports or do I have to set it
programatically.

Assembly
 assembly = Assembly.Load(reportDetails.Substring(reportDetails.IndexOf('.') + 1, reportDetails.LastIndexOf('.') - reportDetails.IndexOf('.') - 1)); foreach (var type in assembly.GetTypes())   {    if (type.FullName == e.Result.ToString())       {         Telerik.ReportViewer.Wpf.ReportViewer _reportViewer = new Telerik.ReportViewer.Wpf.ReportViewer();         ReportViewerPlaceholder.Content = _reportViewer;         Telerik.Reporting.Report rpt = Activator.CreateInstance(typeas Telerik.Reporting.Report;                                          _reportViewer.ReportSource = rpt;    }    }


0
Stef
Telerik team
answered on 10 Dec 2013, 05:57 PM
Hi Oliver,

If you need to change the connection strings, the easiest way is to change the connection stored in the app.config next to the name of the connection string used in the report.
The other approach requires you to instantiate the report, get its DataSource and convert it to Telerik.Reporting.SqlDataSource. Then you can change the ConnectionString property of the data source component. The same applies to inner data items DateSource properties.

In the case of SubReport item, you need to get the item and the underlying report instance, then change its connection string. Finally, assign the SubReport.ReportSource and the ReportViewer.ReportSource.

Regards,
Stef
Telerik

New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

0
Oliver
Top achievements
Rank 1
answered on 11 Dec 2013, 01:19 AM
Hi Stef,

Some of my reports are working and some are not. Is giving me the following error. I'm not sure what to make of it:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Telerik.ReportViewer.Wpf.ReportViewerModel.ApplyValuesOnReportSource(ReportSource rs)
   at Telerik.ReportViewer.Wpf.ReportViewerModel.CreateReportSourceSnapshot(ReportSource source)
   at Telerik.ReportViewer.Wpf.ReportViewerModel.CreateHistoryRecord(ReportSource source, Boolean isTemporary)
   at Telerik.ReportViewer.Wpf.ReportViewerModel.LogHistory(ReportSource source, LogHistoryRecord logHistory, Boolean logTemporaryHistoryRecord)
   at Telerik.ReportViewer.Wpf.ReportViewerModel.RefreshReportCore(Boolean reloadParameters, LogHistoryRecord logHistory)
   at Telerik.ReportViewer.Wpf.ReportViewerModel.RefreshReport()
   at Telerik.ReportViewer.Wpf.ReportViewer.RefreshReport()
   at Telerik.ReportViewer.Wpf.ReportViewer.OnLoaded(Object sender, RoutedEventArgs e)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
0
Oliver
Top achievements
Rank 1
answered on 11 Dec 2013, 07:46 AM
I noticed that reports with more than one sqlDataSources is not working.


I traced it down to on running the following:

Telerik.Reporting.Report rpt = Activator.CreateInstance(typeas Telerik.Reporting.Report;
                                
and tracing the datasources for rpt, there is only one sqldatasources where as it should be more.
Is there a way to instantiate the report to get all sqldatasources available to the report?
0
Stef
Telerik team
answered on 13 Dec 2013, 05:35 PM
Hello Oliver,

The used data source components cannot be accessed through the report instance directly, thus you need to follow the approach described in my previous post. Get a data item and its DataSource property, then convert the DataSource to the specific data source component. The same has to be performed for each data item in the report's Items collection.

In order to provide you more accurate suggestions, please open a support ticket and send us a sample project illustrating the problem and your settings.

Regards,
Stef
Telerik

New HTML5/JS REPORT VIEWER with MOBILE AND TOUCH SUPPORT available in Telerik Reporting Q3 2013! Get the new Reporting version from your account or download a trial.

Tags
General Discussions
Asked by
Oliver
Top achievements
Rank 1
Answers by
Stef
Telerik team
Oliver
Top achievements
Rank 1
Share this question
or