kuppu
kuppu

Reputation: 1

No valid report source is available. in asp.net sap crystal report

I am using Sap Crystal Report in asp.net 2010 It will shows the error no valid report source id available, when i refreshing the report or moving to next page at run time using report viewer tools and this is my coding,

 Dim crdoc5 As New ReportDocument()
 Dim crtablogoninfo5 As New TableLogOnInfo
 Dim crtabs5 As Tables

 If Not IsPostBack Then
      crdoc5.Load(Server.MapPath("CrStaffrecruit.rpt"))
      Session.Add("CrStaffrecruit", crdoc5)
      CrystalReportViewer5.ReportSource = crdoc5
  Else
      CrystalReportViewer5.ReportSource = Session("CrStaffrecruit")
  End If

  crdoc5.Load(Server.MapPath("CrStaffrecruit.rpt"))
  Dim crconninfo5 As New ConnectionInfo()
  rconninfo5.ServerName = "servername"
  crconninfo5.DatabaseName = "databasename"
  crconninfo5.UserID = "sa"
  crconninfo5.Password = ""

  crtabs5 = crdoc5.Database.Tables()
  For Each crtab5 As CrystalDecisions.CrystalReports.Engine.Table In crtabs5
      crtablogoninfo5 = crtab5.LogOnInfo
      crtablogoninfo5.ConnectionInfo = crconninfo5
      crtab5.ApplyLogOnInfo(crtablogoninfo5)
  Next

  CrystalReportViewer5.ReportSource = crdoc5
  CrystalReportViewer5.RefreshReport()

If any one know pls help me... Thanks in advance

Upvotes: 0

Views: 8251

Answers (5)

Shady
Shady

Reputation: 1

I have got this problem several times, and the solution is to save the Report Document variable in a session then in the Page_load put the below code:

if (IsPostBack)
{
    if (Session["reportDocument"] != null)
    {
        ReportDocument cr = new ReportDocument();
        cr = (ReportDocument)Session["reportDocument"];
        CrystalReportViewer1.ReportSource = cr;
        CrystalReportViewer1.DataBind();
    }
}

NB: Don't forget to fill the (Session["reportDocument"]) with the Display button.

Upvotes: 0

aleafonso
aleafonso

Reputation: 2256

Although the following code is in C#, it shouldn't be too difficult to translate it to VB and it should solve your issue:

protected void Page_Load(object sender, EventArgs e)
{
        if (Page.IsPostBack)
        {
            //whatever you do when the page is loaded for the first time
            //this could even be bindReport();
        }
        else
        {
            bindReport();
        }
}

public void bindReport()
{
        ReportDocument rptDoc = new ReportDocument();
        dsSample ds = new dsSample(); // .xsd file name
        DataTable dt = new DataTable();
        // Just set the name of data table
        dt.TableName = "Crystal Report Example";
        dt = getMostDialledNumbers(); //This function populates the DataTable
        ds.Tables[0].Merge(dt, true, MissingSchemaAction.Ignore);
        // Your .rpt file path will be below
        rptDoc.Load(Server.MapPath("yourReportFilePath.rpt"));
        //set dataset to the report viewer.
        rptDoc.SetDataSource(ds);
        CrystalReportViewer1.ReportSource = rptDoc;
        CrystalReportViewer1.RefreshReport();
        //in case you have an UpdatePanel in your page, it needs to be updated
        UpdatePanel1.Update();
}

Upvotes: 1

Khalid Rafique
Khalid Rafique

Reputation: 161

For this please go through the following link

http://forums.sdn.sap.com/thread.jspa?messageID=10951477&#10951477

Upvotes: 1

Chase B. Gale
Chase B. Gale

Reputation: 386

I was experiencing the same problem. In what event are you executing the code you posted? I ask because after much debugging, I discovered that you need to place the code in Page_Load (as opposed to PreRender like I was doing previously...)

Hope this helps.

Upvotes: 0

Related Questions