[英]Crystal Report DataBase Logon Failed Error when going to next page
I have a Asp.net Form with Crystal Report Viewer Control on It. 我有一个带有Crystal Report Viewer控件的Asp.net表单。
On Page_Load Event, I am loading a report & setting a DataSource To it from Database. 关于Page_Load事件,我正在从数据库中加载报告并为其设置数据源。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt= Custom.StaticGeneral.GetDataTable("Select top 100 * From CustVend order by Code desc");
dt.TableName = "CustVend";
dt.AcceptChanges();
DataSet ds = new DataSet();
ds.Tables.Add(dt);
ds.AcceptChanges();
ReportDocument myReportDocument;
myReportDocument = new ReportDocument();
myReportDocument.Load(Server.MapPath("CrystalReport1.rpt"));
myReportDocument.SetDataSource(ds);
CrystalReportViewer1.ReportSource = myReportDocument;
//CrystalReportViewer1.DataBind(); Also Tried This
CrystalReportViewer1.DisplayToolbar = true;
}
}
this is the relevant html 这是相关的HTML
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server"
GroupTreeImagesFolderUrl="" Height="1202px"
ReuseParameterValuesOnRefresh="True" EnableDatabaseLogonPrompt="false"
ToolbarImagesFolderUrl="" ToolPanelWidth="200px" Width="1104px" />
I have set EnableDatabaseLogonPrompt="false" because I am providing my own data source & question of log in does not arise. 我设置了EnableDatabaseLogonPrompt =“ false”,因为我提供了自己的数据源,并且不会出现登录问题。
I get to see the Report when Page is Loaded with my data. 当页面加载有数据时,我可以看到报表。 However, When I Select "Go To Next Page" Link of the crystal report Viewer Control, An Error Pops Up as
但是,当我选择Crystal Report Viewer控件的“转到下一页”链接时,将弹出一个错误,提示为
Error : "Database logon failed." 错误:“数据库登录失败。”
Seems that I am missing out something (probably rebinding the dataset/Report) but can't figure it out... 似乎我遗漏了某些内容(可能是重新绑定了数据集/报表),但无法弄清楚...
I can solve this error by commenting out the Line if (!IsPostBack). 我可以通过注释掉Line if(!IsPostBack)来解决此错误。 but is it the right way to query the Database again & load the whole report every time user is changing a page ?
但是,是每当用户更改页面时再次查询数据库并加载整个报告的正确方法吗?
Or are there Simpler/easier options available.. 还是有更简单/更轻松的选项可用。
The code that loads the report must be execute on every postback. 加载报告的代码必须在每个回发上执行。 Page_Init is the right place where you can put this code (Page_Load can cause some errors).
Page_Init是放置此代码的正确位置(Page_Load可能会导致一些错误)。
Hey, it's reccomended to close ReportDocument on every page unload; 嘿,建议您在每次卸载页面时关闭ReportDocument; this avoid an uncontrolled increase on a Report Counter that will stop the application
这样可以避免报表计数器不受控制地增加而导致应用程序停止运行
protected void Page_Unload(object sender, EventArgs e)
{
if (reportDocument != null)
reportDocument.Close();
}
Put the code in LoadData method that should be called if(!IsPostBack). 将代码放入应该称为if(!IsPostBack)的LoadData方法中。 IsPostBack is used for Ajax calls and it's not the case for CrystalReports.
IsPostBack用于Ajax调用,而CrystalReports不是这种情况。
Here is how I do it: 这是我的方法:
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="myCristalReport.rpt"></Report>
</CR:CrystalReportSource>
<CR:CrystalReportViewer
ID="CrystalReportViewer1"
runat="server"
AutoDataBind="true"
EnableDatabaseLogonPrompt="False"
EnableParameterPrompt="False"
ReportSourceID="CrystalReportSource1"
ToolPanelView="None" />
and in LoadData : 并在LoadData中:
var reportSource = (CrystalReportSource)this.FindControlRecursively("CrystalReportSource1");
reportSource.ReportDocument.SetDatabaseLogon("dbuser", "dbpassword");
reportSource.ReportDocument.SetParameterValue("Month", 2);
.... ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.