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

Failing Telerik Reporting datasource

5 Answers 146 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 23 May 2014, 06:24 PM
We inherited old Telerik 2011 code and our Telerik reports are failing with Telerik 2014 Q1.  We have good reports generated from the earlier version. The SurveyID does have a valid integer but the Datasource is failing.  The following has Bolded text being the failing code:

' Instantialte the report object and assign data sources to report and subreports
Dim Report1 As New Reporting.MstrRpt_LESD_Preview()
Dim SurveyID As New Int32
SurveyID = CInt(Session("LESD_SurveyID"))
Report1.DataSource = LESD.ConfigurePreviewReport(SurveyID)

CType(Report1.Items("detail").Items("SubReport1"), Telerik.Reporting.SubReport).Report.DataSource = LESD.ConfigurePreviewSubReportBase(SurveyID)
CType(Report1.Items("detail").Items("SubReport1"), Telerik.Reporting.SubReport).Parameters.Add("LESD_STE_CHECKED", chkIncludeSteInfo.Checked)
CType(Report1.Items("detail").Items("SubReport1"), Telerik.Reporting.SubReport).Parameters.Add("LESD_STE_NAME", rtbSteName.Text.Trim)
CType(Report1.Items("detail").Items("SubReport1"), Telerik.Reporting.SubReport).Parameters.Add("LESD_STE_PHONE", rtbStePhone.Text.Trim)
CType(Report1.Items("detail").Items("SubReport1"), Telerik.Reporting.SubReport).Parameters.Add("LESD_STE_EMAIL", rtbSteEmail.Text.Trim)
CType(Report1.Items("detail").Items("SubReport1"), Telerik.Reporting.SubReport).Parameters.Add("LESD_STE_COMPCODE", rtbSteCompCode.Text.Trim)
CType(Report1.Items("detail").Items("SubReport2"), Telerik.Reporting.SubReport).Report.DataSource = LESD.ConfigurePreviewSubReportNonBase(SurveyID)

Reporting_Utilities.ReportToPDF(HttpContext.Current, Report1)

End Sub

The excepton says:

System.NullReferenceException was unhandled by user code.
Additional information: Object reference not set to an instance of an object.

The SurveyID is an integer.  It should select a report based on which integer was selected.

Any ideas as to why it is failing?

5 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 27 May 2014, 01:29 PM
Hi Ron,

Currently reports are set in SubReport items through the SubReport.ReportSource object, which expects a report source object. Also report parameters are passed to the sub report through the used report source. The ReportSource.Parameters collection (key-value pairs) is mapped to the report's ReportParameters collection by key.

Please consider the example illustrated in the Changing the connection string dynamically according to runtime data KB article.

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.

 
0
Ron
Top achievements
Rank 1
answered on 27 May 2014, 05:45 PM
Hello Stef,

                 This worked with Telerik 2011 and doesn't work with the 2014 version. We inherited the 2011 version from a rival company but could not obtain that version to move forward and had to purchase the 2014 version. The upgrade conversion tools within the 2014 version did not handle this code correctly.

I have not used C# in years and I know it is similar to VB.NET but your example on the "Changing the connection string dynamically according to runtime data" KB article would require conversion which would delay my troubleshooting process even further.

Could you please help me with the sample I suppiled and not reference me to other examples?  Thank you.
0
Stef
Telerik team
answered on 30 May 2014, 05:28 PM
Hi Ron,

The recommended approach for upgrading from a very old version is to make it gradually as described by my colleague in this forum thread: Errors after upgrading to Q1 2013. If you need to download any older version of Telerik products, feel free to open a support ticket and send us details which products and versions you need to be activated in your account.

About the code snippet in your first post, with Telerik Reporting Q1 2014 SP1 the code should look as follows:
' Instantialte the report object and assign data sources to report and subreports
Dim Report1 As New Reporting.MstrRpt_LESD_Preview()
Dim SurveyID As New Int32
Dim data= LESD.ConfigurePreviewSubReportBase(SurveyID)
SurveyID = CInt(Session("LESD_SurveyID"))
Report1.DataSource = data
Dim mySubReport = CType(Report1.Items.Find("SubReport1",True)(0), Telerik.Reporting.SubReport)
CType(CType(mySubReport.ReportSource, Telerik.Reporting.InstanceReportSource).ReportDocument, Telerik.Reporting.Report).DataSource=data
 
mySubReport.ReportSource.Parameters.Add("LESD_STE_CHECKED", chkIncludeSteInfo.Checked)
mySubReport.ReportSource.Parameters.Add("LESD_STE_NAME", rtbSteName.Text.Trim)
mySubReport.ReportSource.Parameters.Add("LESD_STE_PHONE", rtbStePhone.Text.Trim)
mySubReport.ReportSource.Parameters.Add("LESD_STE_EMAIL", rtbSteEmail.Text.Trim)
mySubReport.ReportSource.Parameters.Add("LESD_STE_COMPCODE", rtbSteCompCode.Text.Trim)
Dim mySubReport1 = CType(Report1.Items.Find("SubReport2",True)(0), Telerik.Reporting.SubReport)
CType(CType(mySubReport1.ReportSource, Telerik.Reporting.InstanceReportSource).ReportDocument, Telerik.Reporting.Report).DataSource=data
 
Reporting_Utilities.ReportToPDF(HttpContext.Current, Report1)
We use the Find method to get the SubReport item.

Note there are other approches to use the same data for master and sub reports.

For example in the sub report you can use a binding to its DataSource property and set it to ReportItem.Parent.Parent.DataObject, which will get the data of the parent item. For more details check How to use the ReportItem.DataObject property in expressions. Then you can use report parameters to filter data as in the How to: Create a Master-Detail Report Using a SubReport Item article.

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.

 
0
Ron
Top achievements
Rank 1
answered on 04 Jun 2014, 04:31 PM
Hello,

         The sample code eliminated the database exceptions from printing but it caused the report to print out nothing instead of the fields it was meant to print in the SubReport.

Ron
0
Ron
Top achievements
Rank 1
answered on 06 Jun 2014, 05:00 PM
I did a Google search for the error "Format of the initialization string does not conform to specification starting at index 0." which was on the PDF that was generated by revised "PrintSurveyRW" Telerik code from a seperated Telerik Support ticket # 822948. I found the solution on http://stackoverflow.com/questions/9040266/how-to-fix-error-format-of-the-initialization-string-does-not-conform-to-speci
and I modified the 3rd answer and changed my code from:

Dim ConnString As String = Reporter_Common.GetConnectionString(DatabaseName)
Dim connection1 As New SqlConnection(ConnString)
to
Dim connection1 As New SqlConnection(ConfigurationManager.ConnectionStrings

 and this worked.  See that support ticket 822948 for more details. Thank you for your efforts.
Tags
General Discussions
Asked by
Ron
Top achievements
Rank 1
Answers by
Stef
Telerik team
Ron
Top achievements
Rank 1
Share this question
or