SAP Knowledge Base Article - Public

1203389 - Err Msg: "Rereading the Database" when using report viewer navigation buttons in Asp.net Web Application

Symptom

When attempting to use the navigation button in the Crystal Report Viewer in a Visual Studio .NET Web application the following error message appears:

"Rereading the Database"

Cause

This error message appears because the report should be loaded in the page init () instead of page load() and we need to load the report in next web forms using Session object.

Resolution

 

To resolve this error message, perform the following code:

 

Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Public Class WebForm1

    Inherits System.Web.UI.Page
    Dim report As New ReportDocument
    Dim crDatabase As Database
    Dim crTables As Tables
    Dim crTable As Table
    Dim crTableLogOnInfo As TableLogOnInfo
    Dim crConnectionInfo As ConnectionInfo
    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
    Dim crParameterFieldDefinition As ParameterFieldDefinition
    Dim crParameterValues As ParameterValues
    Dim crParameterDiscreteValue As ParameterDiscreteValue
    Dim crExportOptions As ExportOptions
    Dim crDiskFileDestinationOptions As DiskFileDestinationOptions

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
        report.Load("C:\Inetpub\wwwroot\cust_app\CrystalReport1.rpt")
        report_logon("pubs", "sa", ".", "sa")
        param("ord", 2)

        crDiskFileDestinationOptions = New DiskFileDestinationOptions
        crDiskFileDestinationOptions.DiskFileName = "C:\exported.pdf"

        crExportOptions = report.ExportOptions
        With crExportOptions
            .DestinationOptions = crDiskFileDestinationOptions
            .ExportDestinationType = ExportDestinationType.DiskFile
            .ExportFormatType = ExportFormatType.PortableDocFormat
        End With

        report.Export()

        CrystalReportViewer1.ReportSource = report


    End Sub

Public Sub report_logon(ByVal dbase As String, ByVal pwd As String, ByVal server As String, ByVal uid As String)
        crConnectionInfo = New ConnectionInfo
        With crConnectionInfo
            .DatabaseName = dbase
            .Password = pwd
            .ServerName = server
            .UserID = uid
        End With

        crDatabase = report.Database
        crTables = crDatabase.Tables

        For Each crTable In crTables
            crTableLogOnInfo = crTable.LogOnInfo
            crTableLogOnInfo.ConnectionInfo = crConnectionInfo
            crTable.ApplyLogOnInfo(crTableLogOnInfo)
        Next
    End Sub

   Public Sub param(ByVal paramname As String, ByVal paramvalue As Object)

        crParameterFieldDefinitions = report.DataDefinition.ParameterFields
        crParameterFieldDefinition = crParameterFieldDefinitions.Item(paramname)

        crParameterValues = crParameterFieldDefinition.CurrentValues

        crParameterDiscreteValue = New ParameterDiscreteValue
        crParameterDiscreteValue.Value = paramvalue

        crParameterValues.Add(crParameterDiscreteValue)

        crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)

 

        "Load the report on the next page using session object"

             Page_init()

Initialize component ()

Session("crReportDocument")= new reportdocument
Session("crReportDocument").load("c:\report1.rpt")

End sub

Page_load()

CrystalReportviewer1.reportsource= session ("crReportDocument")


This will resolve the issue.

Keywords

rereading the database , KBA , BI-RA-CR , Crystal Reports designer or BusinessViews Manager , How To

Product

SAP Crystal Reports 10.0