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:

Troubleshooting
Research
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
        Try
            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)
                        Else
                            crParameterDiscreteValue.Value = vbNullString
                        End If
                        crParameterValues = objReport.DataDefinition.ParameterFields(strVal(0)).CurrentValues
                        crParameterValues.Add(crParameterDiscreteValue)
                        objReport.DataDefinition.ParameterFields(strVal(0)).ApplyCurrentValues(crParameterValues)
                    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
                crvReports.Show()
                crvReports.Refresh()
                frmViewer.Text = "Report Viewer"
                frmViewer.Width = 896
                frmViewer.Height = 416
                frmViewer.WindowState = FormWindowState.Maximized
                frmViewer.Controls.Add(crvReports)
                crvReports.Anchor = CType((((AnchorStyles.Top Or AnchorStyles.Bottom) _
                    Or AnchorStyles.Left) Or AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
                'frmViewer.Show()
                frmRpt = frmViewer
            Else
                crvReports.ReportSource = Nothing
                crvReports.ReportSource = objReport
                crvReports.Show()
            End If
			crvReports.ShowLogo = False
			crvReports.ReportSource = Nothing
            crvReports.ReportSource = objReport
            If bPrint Then
                frmRpt = Nothing
                objReport.PrintToPrinter(1, False, 0, 0)
            Else
                crvReports.Show()
            End If
            Application.DoEvents()
            Return True
        Catch ex As System.Exception
			MessageBox.Show("Error Creating Report " & ex.Message, "Error In View Crystal Report DS", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            Erase strParVal
            Erase strVal
        End Try
    End Function

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

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

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