Visual studio 2010 没有可用的有效报告源。在asp.net sap crystal报表中

Visual studio 2010 没有可用的有效报告源。在asp.net sap crystal报表中,visual-studio-2010,crystal-reports,crystal-reports-2010,Visual Studio 2010,Crystal Reports,Crystal Reports 2010,我正在asp.net 2010中使用Sap Crystal Report 当我使用报表查看器工具在运行时刷新报表或移动到下一页时,它将显示错误无可用的有效报表源id 这是我的代码 Dim crdoc5 As New ReportDocument() Dim crtablogoninfo5 As New TableLogOnInfo Dim crtabs5 As Tables If Not IsPostBack Then crdoc5.Load(Server.MapPath(

我正在asp.net 2010中使用Sap Crystal Report 当我使用报表查看器工具在运行时刷新报表或移动到下一页时,它将显示错误
无可用的有效报表源id
这是我的代码

 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()
如果有人知道,请帮助我。。。
提前谢谢

我也遇到了同样的问题。您在什么情况下执行发布的代码?我这样问是因为经过大量调试后,我发现您需要将代码放入页面加载中(而不是像我以前那样进行预渲染…)


希望这能有所帮助。

有关这一点,请浏览以下链接


尽管下面的代码是用C#编写的,但将其翻译成VB应该不会太难,它应该可以解决您的问题:

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();
}

我多次遇到此问题,解决方法是将报告文档变量保存在会话中,然后在
页面加载
中输入以下代码:

if (IsPostBack)
{
    if (Session["reportDocument"] != null)
    {
        ReportDocument cr = new ReportDocument();
        cr = (ReportDocument)Session["reportDocument"];
        CrystalReportViewer1.ReportSource = cr;
        CrystalReportViewer1.DataBind();
    }
}
注意:
不要忘记用显示按钮填写
(会话[“reportDocument”])

浏览以下链接。我用那个解决方案解决了同样的问题


对于那些将代码从VS2008迁移/复制到[VS2010&CR 13.0.2]环境的人:报告的初始加载应在“Page_Init”(与SAP论坛中提到的示例相反,因为使用导航按钮时,不会设置您进入第二页)。同样,在VS2010中也不需要“Page_Unload”事件处理程序。我记得使用crystal reports 10在VS2008项目中重新调解页面导航错误。