Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Push Method Failed to retrieve data from database

Avatar of tomnorra
tomnorra asked on
Crystal ReportsVisual Basic.NETMicrosoft SQL Server 2005
19 Comments1 Solution759 ViewsLast Modified:
Ok this one has puzzled me far too long now. I have a crystal report created using the push method. When I create the dataset and pass it to the report everything seems to work until the point the viewer tries to show the results. At this point I get the attached Error(Failed to retrieve data from database).
 Error MessageThe puzzling thing is this is a push method, the report should not be trying to retrieve anything from the database and the dataset is returned without issue from the database. I have recreated this report multiple times and every time the same result. I have modified the SP multiple times thinking it might be something to do with SQL Server 2005, same results. I created the report as a pull method as well, this actually worked correctly but I don't want any reports pulling data as company policy is to push a result to the report. All other reports(more than 200) using push method work fine because in pull method you have to set connection info, but as a push report this one just wants to be a pain.
Here is some code that defines the basics of what is being done:
sStartDate = Convert.ToDateTime(“2010-06-01 14:00:01”).ToString("yyyy-MM-dd HH:mm:ss")
sEndDate = Convert.ToDateTime(“2010-06-02 08:00:00”).ToString("yyyy-MM-dd HH:mm:ss")
objRptDS = m_objReports.GetDataSet("Execute spVaultLogImpProcRpt '" & sStartDate & "', '" & sEndDate & "'")
If (objRptDS Is Nothing) OrElse objRptDS.Tables.Count = 0 OrElse objRptDS.Tables(0).Rows.Count = 0 _
OrElse Not m_objReports.ViewCrystalReportDS(sTemplatePath & "rptVLIP.rpt", Nothing, "@dStartDateTime~" & sStartDate & "|@dEndDateTime~" & sEndDate, , frmRpt, , objRptDS) Then
    MessageBox.Show(sDefaultMsg, sDefaultTitle, MessageBoxButtons.OK, MessageBoxIcon.Information)
End If

Public Function ViewCrystalReportDS(ByVal sReportName As String, _
                    ByRef crvReports As CrystalDecisions.Windows.Forms.CrystalReportViewer, _
                    Optional ByVal sParams As String = "", Optional ByVal sSelectionFormula As String = "", _
                    Optional ByRef frmRpt As System.Windows.Forms.Form = Nothing, _
                    Optional ByVal bPrint As Boolean = False, Optional ByVal dsRpt As DataSet = Nothing) As Boolean
        Dim intCounter As Int32 = 0
        Dim intCounter1 As Int32 = 0
        Dim objReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
		Dim crParameterDiscreteValue As New CrystalDecisions.Shared.ParameterDiscreteValue
        Dim crParameterValues As CrystalDecisions.Shared.ParameterValues
		Dim strParVal() As String
        Dim strVal() As String
        Dim iLoop As Int32 = 0
            objReport.Load(sReportName) 'Load The Report
            'Pass the dataset to the report
			If Not (dsRpt Is Nothing) Then objReport.SetDataSource(dsRpt.Tables(0)) Else Return False
            'Check If There Are Parameters In Report.
            intCounter = objReport.DataDefinition.ParameterFields.Count
            'Since ParameterFields Collection Picks Up The Selection Formula In The Count Even Though
            'It Is Not A Parameter We Have To Check If It Is A Formula When Count Is 1
            If intCounter = 1 Then
                If InStr(objReport.DataDefinition.ParameterFields(0).ParameterFieldName, ".", CompareMethod.Text) > 0 Then intCounter = 0
            End If
            'If There Are Parameters And String Is Not Empty
            If intCounter > 0 And sParams.Trim.Length > 0 Then
                strParVal = sParams.Split(Convert.ToChar("|")) 'Split The Parameter String
                For iLoop = 0 To UBound(strParVal)
                    If InStr(strParVal(iLoop), "~") > 0 Then
                        strVal = strParVal(iLoop).Split(Convert.ToChar("~")) 'Split The Values
                        'Apply Values To Parameters.
                        If strVal(1).ToUpper <> "NULL" Then
                            crParameterDiscreteValue.Value = strVal(1)
                            crParameterDiscreteValue.Value = vbNullString
                        End If
                        crParameterValues = objReport.DataDefinition.ParameterFields(strVal(0)).CurrentValues
                    End If
                Next iLoop
            End If
			'If Selection Formula Passed Then Use Formula
            If sSelectionFormula.Length > 0 Then objReport.RecordSelectionFormula = sSelectionFormula
            'Set Report Object To Show Report.
            If (crvReports Is Nothing) Then
                Dim frmViewer As New Windows.Forms.Form
                crvReports = New CrystalDecisions.Windows.Forms.CrystalReportViewer
                crvReports.ReportSource = Nothing
                crvReports.ReportSource = objReport
                crvReports.Left = 0
                crvReports.Top = 0
                crvReports.Name = "crvReports"
                crvReports.Width = 872
                crvReports.Height = 368
                crvReports.TabIndex = 0
                'crvReports.DisplayStatusBar = True
                crvReports.DisplayGroupTree = False
                frmViewer.Text = "Report Viewer"
                frmViewer.Width = 896
                frmViewer.Height = 416
                frmViewer.WindowState = FormWindowState.Maximized
                crvReports.Anchor = CType((((AnchorStyles.Top Or AnchorStyles.Bottom) _
                    Or AnchorStyles.Left) Or AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
                frmRpt = frmViewer
                crvReports.ReportSource = Nothing
                crvReports.ReportSource = objReport
            End If
			crvReports.ShowLogo = False
			crvReports.ReportSource = Nothing
            crvReports.ReportSource = objReport
            If bPrint Then
                frmRpt = Nothing
                objReport.PrintToPrinter(1, False, 0, 0)
            End If
            Return True
        Catch ex As System.Exception
			MessageBox.Show("Error Creating Report " & ex.Message, "Error In View Crystal Report DS", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Erase strParVal
            Erase strVal
        End Try
    End Function

Why is their failure to retrieve something that has already been retrieved?
Avatar of tomnorra

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 19 Comments.
See Answers