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

SubReport design-time connection string to the run-time connection string

3 Answers 79 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 18 Jun 2014, 01:28 PM
This code worked with Telerik 2011 but fails to work with Telerik 2014.  It generates: "An exception of type 'System.NullReferenceException' occurred in Reporting.dll but was not handled in user code".

   " Public Shared Sub ConfigureCslReport(ByRef Report1 As Telerik.Reporting.Report)
         ' Change the design-time connection string to the run-time connection string
 
        CType(CType(Report1.Items("ReportFooterSection1").Items("SubReport1"), Telerik.Reporting.SubReport).Report.DataSource, Telerik.Reporting.SqlDataSource).ConnectionString = Reporter_Common.GetConnectionString("SHPR")
 
        CType(CType(Report1.Items("ReportFooterSection1").Items("SubReport2"), Telerik.Reporting.SubReport).Report.DataSource, Telerik.Reporting.SqlDataSource).ConnectionString = Reporter_Common.GetConnectionString("SHPR")
 
        CType(CType(Report1.Items("ReportFooterSection1").Items("SubReport3"), Telerik.Reporting.SubReport).Report.DataSource, Telerik.Reporting.SqlDataSource).ConnectionString = Reporter_Common.GetConnectionString("SHPR")
 
        CType(CType(Report1.Items("ReportFooterSection1").Items("SubReport4"), Telerik.Reporting.SubReport).Report.DataSource, Telerik.Reporting.SqlDataSource).ConnectionString = Reporter_Common.GetConnectionString("SHPR")
     End Sub"

Since 90% of the report works, why do these 4 SubReports in the Footer section fail?  The "Reporter_Common.GetConnectionString("SHPR")"  just returns the SQL connection to the database and is used without errors in the rest of the report.

Any ideas?

3 Answers, 1 is accepted

Sort by
0
Ron
Top achievements
Rank 1
answered on 18 Jun 2014, 01:34 PM
I forgot to mention I am using Telerik 2014 Q1 and request a VB.NET response.  The original Telerik 2011 development system where the code was developed belongs to another company and we inherited the code and had to immediately upgrade to Telerik 2014 Q1 to get it back to operational status because we could not go back to that 2011 version.
0
Ron
Top achievements
Rank 1
answered on 18 Jun 2014, 05:14 PM
I tried modifying my code to use an instance and was able to eliminate the Datasource error but the data does not get imported from the databse to the SubReports on the Report1 form.  Here is the revised code:
 
" Public Shared Sub ConfigureCslReport(ByRef Report1 As Telerik.Reporting.Report)
         ' Change the design-time connection string to the run-time connection string
 
        Dim subReportItem1 As Telerik.Reporting.SubReport = CType(Report1.Items("ReportFooterSection1").Items("SubReport1"), Telerik.Reporting.SubReport)
 
        Dim irs1 As New Telerik.Reporting.InstanceReportSource()
 
        Dim subReportObject1 As New SubRpt_Shipres_CSL_Area1
 
        subReportObject1.DataSource = Report1.DataSource.
 
        irs1.ReportDocument = subReportObject1
 
        subReportItem1.ReportSource = irs1
 
        Dim subReportItem2 As Telerik.Reporting.SubReport = CType(Report1.Items("ReportFooterSection1").Items("SubReport2"), Telerik.Reporting.SubReport)
 
        Dim irs2 As New Telerik.Reporting.InstanceReportSource()
 
        Dim subReportObject2 As New SubRpt_Shipres_CSL_Area2
 
        subReportObject2.DataSource = Report1.DataSource
 
        irs2.ReportDocument = subReportObject2
 
        subReportItem2.ReportSource = irs2
 
        Dim subReportItem3 As Telerik.Reporting.SubReport = CType(Report1.Items("ReportFooterSection1").Items("SubReport3"), Telerik.Reporting.SubReport)
 
        Dim irs3 As New Telerik.Reporting.InstanceReportSource()
 
        Dim subReportObject3 As New SubRpt_ShipRes_CSL_Notes1
 
        subReportObject3.DataSource = Report1.DataSource
 
        irs3.ReportDocument = subReportObject3
 
        subReportItem3.ReportSource = irs3
 
        Dim subReportItem4 As Telerik.Reporting.SubReport = CType(Report1.Items("ReportFooterSection1").Items("SubReport4"), Telerik.Reporting.SubReport)
 
        Dim irs4 As New Telerik.Reporting.InstanceReportSource()
 
        Dim subReportObject4 As New SubRpt_ShipRes_CSL_Notes2
 
        subReportObject4.DataSource = Report1.DataSource
 
        irs4.ReportDocument = subReportObject4
 
        subReportItem4.ReportSource = irs4
 
End Sub"
0
Stef
Telerik team
answered on 20 Jun 2014, 07:30 AM
Hello Ron,

In your support ticket on the same question I suggested you the following:
"
The recommended approach is to change the connection strings at run-time by using the report instance prior to displaying it. Consider the example in the Changing the connection string dynamically according to runtime data KB article.
.......

The provided code should work as expected if it is called before assigning the report to the viewer.

If all sub reports are supposed to use the same data as the master, I can suggest you an approach with bindings of the sub reports' DataSource properties to the master report's assigned data by using the ReportItem object. Consider the attached demo project
.
"

Regards,
Stef
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

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