Crystal Report Viewer不接受登录信息 [英] Crystal Report Viewer Not Accepting Login Info
问题描述
我正在尝试制作一个简单的Crystal Report Viewer应用程序,但无法让Viewer设置登录信息.基本上我想做的就是单击一个按钮,它应该打开一个报告.我认为很简单,但显然没有.这是我的代码
I am trying to make a simple crystal report viewer application and I cannot get the viewer to set the login info. Basically want I want to do is on the click of a button it should open a report. Pretty simple I thought but apparently not. Here's my code
private void button1_Click(object sender, EventArgs e)
{
ConnectionInfo connInfo = new ConnectionInfo();
connInfo.ServerName = "SERVER NAME";
connInfo.DatabaseName = "DATABASE NAME";
connInfo.UserID = "USERNAME";
connInfo.Password = "PASSWORD";
crystalReportViewer1.ReportSource = GetReportSource(connInfo);
crystalReportViewer1.RefreshReport();
}
private ReportDocument GetReportSource(ConnectionInfo connInfo)
{
ReportDocument document = new ReportDocument();
document.Load("REPORTPATH");
document.SetParameterValue(0, "04/02/2014");
document.SetParameterValue(1, "04/03/2014");
TableLogOnInfos logonInfos = new TableLogOnInfos();
TableLogOnInfo logonInfo = new TableLogOnInfo();
Tables tables;
tables = document.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
{
logonInfo = table.LogOnInfo;
logonInfo.ConnectionInfo = connInfo;
table.ApplyLogOnInfo(logonInfo);
}
return document;
}
最糟糕的是,此代码可以在我的一台计算机上正常运行,但不能在我希望使用的计算机上运行.同样,此代码完全可以在我的一台计算机上编译并运行,而不能在另一台计算机上运行,并且我无法弄清为什么.上帝,我希望有人能提供帮助.
The worst part is that this code works FINE on one of my computers but not the one I WANT it to work on. Again, this code totally compiles and works on one of my computers but not the other and I cannot figure out for the life of me why. God I hope someone can help.
当我运行该程序并单击该按钮时,它会提示我输入用户名和密码,但是,当我输入该用户名和密码时,它会显示登录失败".另一个问题是,登录时未填充数据库"字段形式,即使它应该是.
When I run the program and click the button, it prompts me for the username and password, however when I enter it, it says "Login failed" another problem is that the "Database" field isn't populated on the login form even though it should be.
推荐答案
好的,我解决了这个问题.尚不完全确定为什么这样做有效,但我将在这里张贴我的后代内容,因为在这里找不到任何人可以帮助我.
OK I solved this. Not entirely sure why this worked but I'll post what I did here for posterity since I could not find anyone able to help me here.
首先,我在出现问题的计算机上安装了Crystal Reports.(我的公司有2011年的许可证,所以我安装了2011年)
First I installed Crystal Reports on the computer that was giving me the problem. (my company has a license for 2011 so I installed 2011)
接下来,我打开报表(使用Crystal Reports 2011程序)并尝试对其进行预览,它提示我输入登录信息,因此我提供了登录信息并让该报告生成预览.
Next, I opened the report (using the Crystal Reports 2011 program) and tried to preview it, it prompted me for login info so I gave the login info and let the report generate a preview.
最后,我运行了程序,它开始工作了!
Finally I ran the program and it worked!
因此,我认为问题主要是通过安装Crystal报表解决的,但是我认为仍然有必要进入报表本身并确保它可以生成预览.
So I think the problem was mostly solved by installing crystal reports, but I think it was still necessary to go into the report itself and make sure it could generate a preview.
这篇关于Crystal Report Viewer不接受登录信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!