Crystal reports, why is it asking for database login even after I provided the details?(水晶报表,为什么我提供了详细信息后仍然要求登录数据库?)
问题描述
我正在生成一个报告,但问题是即使我提供了凭据,当包含 CrystalReport 的表单打开时,它仍然要求我提供它们,最糟糕的是,我没有输入任何内容在那里,只需单击完成,它就会加载报告.那么,如果不需要凭据(或其他),它为什么要问我?
I am generating a report, but the problem is even though I've supplied credentials, when the form containing the CrystalReport opens up, it still asks me for them, and the worst part is, I don't enter any thing in there, and just click finish, and it loads the report. So, if there is no need for credentials (or whatever) why is it asking me?
这是代码
private void MainReport_Load(object sender, EventArgs e)
{
var constr = string.Empty;
constr = Application.StartupPath;
if (Generate.bForProjects)
constr = Path.Combine(constr, @"ReportsProjects.rpt");
else
constr = Path.Combine(constr, @"ReportsOther.rpt");
var myConInfo = new CrystalDecisions.Shared.TableLogOnInfo();
reportDocument1.Load(constr);
myConInfo.ConnectionInfo.DatabaseName = "ProjectData.mdb";
myConInfo.ConnectionInfo.ServerName = Application.StartupPath + @"DataProjectData.mdb";
myConInfo.ConnectionInfo.Password = "";
myConInfo.ConnectionInfo.UserID = "";
reportDocument1.Database.Tables[0].ApplyLogOnInfo(myConInfo);
reportDocument1.Refresh();
crystalReportViewer1.ReportSource = reportDocument1;
crystalReportViewer1.Width = this.Width - 50;
crystalReportViewer1.Height = this.Height - 100;
}
当表单加载时,会弹出这个屏幕
When the form loads, this screen pop ups
而且,当出现这种情况时,我什么都不输入!那就对了!我只需单击完成,它就会完美地加载报告!那么,如果它不需要任何东西,为什么它会要求我登录?
推荐答案
当我们将水晶报表连接到与设计/创建它的数据库不同的数据库时,我们遇到了很多问题.我们最终创建了以下函数来正确设置它.它递归地设置所有报表表和子报表的连接.
We have lots of problems when we came to connect a crystal report to a different database to the one it was designed / created against. We ended up creating the following function to set it up correctly. It recursively sets the connection on all report tables and sub reports.
我似乎还记得,如果报告是使用集成 Windows 身份验证设计的,并且使用简单的用户名和密码运行,我们就会遇到问题.因此,我们始终确保使用简单的用户名和密码连接到数据库来设计报告.
Also I seem to remember we had problems if the report was designed with Integrated Windows Authentications, and run with a simple username and password. So we always made sure we designed the reports with a simple username and password connection to the database.
private static void SetConnection(ReportDocument report, string databaseName, string serverName, string userName, string password)
{
foreach (Table table in report.Database.Tables)
{
if (table.Name != "Command")
{
SetTableConnectionInfo(table, databaseName, serverName, userName, password);
}
}
foreach (ReportObject obj in report.ReportDefinition.ReportObjects)
{
if (obj.Kind != ReportObjectKind.SubreportObject)
{
return;
}
var subReport = (SubreportObject)obj;
var subReportDocument = report.OpenSubreport(subReport.SubreportName);
SetConnection(subReportDocument, databaseName, serverName, userName, password);
}
}
private static void SetTableConnectionInfo(Table table, string databaseName, string serverName, string userName, string password)
{
// Get the ConnectionInfo Object.
var logOnInfo = table.LogOnInfo;
var connectionInfo = logOnInfo.ConnectionInfo;
// Set the Connection parameters.
connectionInfo.DatabaseName = databaseName;
connectionInfo.ServerName = serverName;
connectionInfo.Password = password;
connectionInfo.UserID = userName;
table.ApplyLogOnInfo(logOnInfo);
if (!table.TestConnectivity())
{
throw new ApplicationException(Resource.UnableToConnectCrystalReportToDatabase);
}
table.Location = Database + "." + "dbo" + "." + table.Location;
}
这篇关于水晶报表,为什么我提供了详细信息后仍然要求登录数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:水晶报表,为什么我提供了详细信息后仍然要求登录数据库?
基础教程推荐
- SSE 浮点算术是否可重现? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- MS Visual Studio .NET 的替代品 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- c# Math.Sqrt 实现 2022-01-01