locked
Sporadic issue with ReportViewer - "A data source instance has not been supplied for the data source" RRS feed

  • Question

  • User-883621491 posted

    Hi. I have an application that has been working fine for at least 2 years. Around January of this year, some of our tech people made a bunch of changes in the virtual infrastructure, physical networking, etc. to the servers hosting our ASP.NET apps. After these changes (of which there were far too many to be able to isolate), I am now having problems with one of my apps

    The app uses a ReportViewer control to display a report. It works most of the time, but sporadically, and such that I can't reproduce it, the users will get an error "A data source instance has not been supplied for the data source", and the report will not display. I am trying to figure out how to either 1) find out from Windows error logs or some other method what is causing this to happen, or 2) be able to work around it so that the user can try to re-run the report if it happens. Here is a sample of the code I am using. I have added the Try...Catch block and the display of a "try again" button to let them try the report again. This error-handling change has not been pushed out yet, so I am not sure if this will help, but I hope so, at least so they can try again. The report they complain about not working the most is the one handled by the report type "KeyReturn" in the code.

    Please advise if there is a particular Windows error log I can try to look at to see what is causing this problem, or if there is some other way that I don't know about that I can use to prevent this from happening. Thank you.

        Protected Sub PrintReport()
            Dim BadCall As Boolean = False
    
            Try
                rvReportViewer.LocalReport.DataSources.Clear()
                Select Case lblRepType.Text
                    Case "KeyReceipt"
                        rvReportViewer.LocalReport.ReportPath = "Reports\KeyReceipt.rdlc"
    
                        Dim reportParameters(0) As ReportParameter
                        reportParameters(0) = New ReportParameter("Building", lblBuildingName.Text)
                        rvReportViewer.LocalReport.SetParameters(reportParameters)
    
                        ObjectDSKeyReceipt.SelectParameters("CustID").DefaultValue = lblCustID.Text
                        ObjectDSKeyReceipt.SelectParameters("Building").DefaultValue = lblBuildingCode.Text
                        ObjectDSKeyReceipt.SelectParameters("incident").DefaultValue = lblRepOptions.Text
                        ObjectDSKeyReceipt.SelectParameters("RepDate").DefaultValue = lblRepOptions2.Text
                        ''
                        ObjectDSKeyReceiptSubKeycode.SelectParameters("CustID").DefaultValue = lblCustID.Text
                        ObjectDSKeyReceiptSubKeycode.SelectParameters("Building").DefaultValue = lblBuildingCode.Text
                        ObjectDSKeyReceiptSubKeycode.SelectParameters("incident").DefaultValue = lblRepOptions.Text
                        ObjectDSKeyReceiptSubKeycode.SelectParameters("RepDate").DefaultValue = lblRepOptions2.Text
                        ''
                        ObjectDSKeyReceiptSubCurrentCharge.SelectParameters("CustID").DefaultValue = lblCustID.Text
                        ObjectDSKeyReceiptSubCurrentCharge.SelectParameters("Building").DefaultValue = lblBuildingCode.Text
                        ObjectDSKeyReceiptSubCurrentCharge.SelectParameters("incident").DefaultValue = lblRepOptions.Text
                        ObjectDSKeyReceiptSubCurrentCharge.SelectParameters("RepDate").DefaultValue = lblRepOptions2.Text
    
                        rvReportViewer.LocalReport.DataSources.Add(New ReportDataSource("DataSetKeyReceipt", "ObjectDSKeyReceipt"))
                        AddHandler rvReportViewer.LocalReport.SubreportProcessing, AddressOf SetKeyReceiptSubDataSource
                    Case "KeyReturn"
                        rvReportViewer.LocalReport.ReportPath = "Reports\KeyReturn.rdlc"
    
                        Dim reportParameters(0) As ReportParameter
                        reportParameters(0) = New ReportParameter("Building", lblBuildingName.Text & " Key Receipt")
                        rvReportViewer.LocalReport.SetParameters(reportParameters)
    
                        ObjectDSKeyReturn.SelectParameters("CustID").DefaultValue = lblCustID.Text
                        ObjectDSKeyReturn.SelectParameters("Building").DefaultValue = lblBuildingCode.Text
                        ObjectDSKeyReturn.SelectParameters("incident").DefaultValue = lblRepOptions.Text
                        ObjectDSKeyReturn.SelectParameters("RepDate").DefaultValue = lblRepOptions2.Text
                        ''
                        ObjectDSKeyReturnSubCharges.SelectParameters("CustID").DefaultValue = lblCustID.Text
                        ObjectDSKeyReturnSubCharges.SelectParameters("Building").DefaultValue = lblBuildingCode.Text
                        ObjectDSKeyReturnSubCharges.SelectParameters("incident").DefaultValue = lblRepOptions.Text
                        ObjectDSKeyReturnSubCharges.SelectParameters("RepDate").DefaultValue = lblRepOptions2.Text
    
                        rvReportViewer.LocalReport.DataSources.Add(New ReportDataSource("DataSetKeyReturn", "ObjectDSKeyReturn"))
                        AddHandler rvReportViewer.LocalReport.SubreportProcessing, AddressOf SetKeyReturnSubDataSource
                    Case "LateKeyNotification"
                        rvReportViewer.LocalReport.ReportPath = "Reports\LateKey.rdlc"
    
                        Dim reportParameters(0) As ReportParameter
                        reportParameters(0) = New ReportParameter("Building", lblBuildingName.Text)
                        rvReportViewer.LocalReport.SetParameters(reportParameters)
    
                        ObjectDSLateKey.SelectParameters("CustID").DefaultValue = lblCustID.Text
                        ObjectDSLateKey.SelectParameters("Building").DefaultValue = lblBuildingCode.Text
                        ObjectDSLateKey.SelectParameters("incident").DefaultValue = lblRepOptions.Text
    
                        rvReportViewer.LocalReport.DataSources.Add(New ReportDataSource("DataSetLateKey", "ObjectDSLateKey"))
                    Case "KeysOut"
                        rvReportViewer.LocalReport.ReportPath = "Reports\KeysOut.rdlc"
    
                        Dim reportParameters(0) As ReportParameter
                        reportParameters(0) = New ReportParameter("BuildingName", lblBuildingName.Text)
                        rvReportViewer.LocalReport.SetParameters(reportParameters)
    
                        ObjectDSKeysOut.SelectParameters("Building").DefaultValue = lblBuildingCode.Text
    
                        rvReportViewer.LocalReport.DataSources.Add(New ReportDataSource("DataSetKeysOut", "ObjectDSKeysOut"))
                    Case Else
                        BadCall = True
                End Select
                If Not BadCall Then
                    rvReportViewer.ProcessingMode = ProcessingMode.Local
                    rvReportViewer.Visible = True
                    rvReportViewer.LocalReport.Refresh()
                Else
                    divReports.Visible = False
                    divButtons.Visible = True
                    lblError.Text = "There was an error calling this page to print a report. Please close the window/tab. Report requested was " & lblRepType.Text
                    btnReprintReport.Visible = False
                End If
            Catch ex As Exception
                divReports.Visible = False
                divButtons.Visible = True
                lblError.Text = "There was an error calling this page to print a report. Please close the window/tab, or try the report again. " &
                    "Report requested was '" & lblRepType.Text & "'. The error reported was: " & ex.Message
                btnReprintReport.Visible = True
            End Try
        End Sub
    	
        Protected Sub SetKeyReceiptSubDataSource(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
            e.DataSources.Add(New ReportDataSource("DataSetKeyReceipt_SubReportKeycode", "ObjectDSKeyReceiptSubKeycode"))
            e.DataSources.Add(New ReportDataSource("DataSetKeyReceipt_SubReportCurrentCharge", "ObjectDSKeyReceiptSubCurrentCharge"))
            e.DataSources.Add(New ReportDataSource("DataSetKeyReceipt_SubReportRecoreCharges", "ObjectDSKeyReceiptSubRecoreCharges"))
        End Sub
    
        Protected Sub SetKeyReturnSubDataSource(ByVal sender As Object, ByVal e As SubreportProcessingEventArgs)
            e.DataSources.Add(New ReportDataSource("DataSetKeyReturn_SubReportCharges", "ObjectDSKeyReturnSubCharges"))
        End Sub
    
    

    Friday, March 24, 2017 7:07 PM

All replies

  • User-2057865890 posted

    Hi M-Clark,

    A data source instance has not been supplied for the data source

    Please ensure that dataset names are same. The error message indicates the dataset name which you have assigned to report viewer and the dataset name which you use in code behind is different.

    Best Regards,

    Chris

    Tuesday, March 28, 2017 7:10 AM
  • User-883621491 posted

    Thanks for your reply. I'm assuming you saw where I mentioned that it is sporadic? The code works fine 99% of the time, there is just something that happens that causes it to give this error sometimes. I cannot reproduce it because it is so random. If I were assigning the wrong dataset name, it would be happening all the time. I need to know what types of things might cause this. Network issues? Sessions timing out? I need to know how I can troubleshoot what is causing it, via Windows Error logs, or something.

    The way this thing works is:

    1) User clicks a button to complete a process (i.e. returning a key)

    2) Button does some work, then calls a page with the reportviewer code to show the receipt

    3) Page with reportviewer takes session variables from the calling page and stores them in hidden labels, then builds the query parameters, etc.

    4) Report is shown

    Steps 3 and 4 are shown in the code in my original post. As I mentioned also, this worked fine for a long time (around 2 years) before all the behind the scenes server and networking changes, at which time this started. Therefore, I don't believe it is the code, per se, but I need to try to track down what situation causes the error to happen.

    Wednesday, March 29, 2017 1:51 PM
  • User-2057865890 posted

    Hi M-Clark,

    I need to know how I can troubleshoot what is causing it, via Windows Error logs, or something.

    If applications runn under IIS. The browser itself often produces a specific error or set of errors that is enough to resolve the issues. Sometimes you’ll need more information, you could analyze IIS log files in an effort to determine the cause when an application that is hosted on IIS is failing or other issues. 

    By default, IIS log files are located in the following directories:

    IIS 7 and later: %SystemDrive%\inetpub\logs\LogFiles

    You could also go to Administrative Tools, and then click Computer ManagementEvent Viewer is listed under the System Tools node. The benefit of this display is that IIS Manager is in the same window under the Applications and Services node.

    reference:

    https://msdn.microsoft.com/en-us/magazine/dn519926.aspx

    https://msdn.microsoft.com/en-us/library/ms524984(v=vs.90).aspx

    Best Regards,

    Chris

    Thursday, March 30, 2017 7:54 AM