水晶报表,为什么它要求数据库登录,即使我提供了详细信息? [英] Crystal reports, why is it asking for database login even after I provided the details?

查看:173
本文介绍了水晶报表,为什么它要求数据库登录,即使我提供了详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成一个报告,但问题是即使我提供了凭据,当包含CrystalReport的窗体打开,它仍然问我,他们,最糟糕的是,我不输入任何东西在那里,只需点击完成,它加载报告。



这是代码

pre> private void MainReport_Load(object sender,EventArgs e)
{
var constr = string.Empty;
constr = Application.StartupPath;
if(Generate.bForProjects)
constr = Path.Combine(constr,@Reports\Projects.rpt);
else
constr = Path.Combine(constr,@Reports\Other.rpt);

var myConInfo = new CrystalDecisions.Shared.TableLogOnInfo();
reportDocument1.Load(constr);
myConInfo.ConnectionInfo.DatabaseName =ProjectData.mdb;
myConInfo.ConnectionInfo.ServerName = Application.StartupPath + @\Data\ProjectData.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;
}

加载表单时,此屏幕弹出



>



当这种情况出现时,我不输入任何内容!那就对了!我只需点击完成,它完全加载报告!

解决方案

当我们将一个水晶报表连接到一个不同的数据库时,我们遇到了很多问题。我们最终创建了以下函数来正确设置它。它递归地设置所有报表和子报表上的连接。



同样,我似乎记得,如果报表是使用集成Windows身份验证设计的,简单的用户名和密码。所以我们总是确保我们用一个简单的用户名和密码连接到数据库来设计报告。

  private static void SetConnection(ReportDocument报表,字符串databaseName,字符串serverName,字符串userName,字符串密码)
{
foreach(report.Database.Tables中的表表)
{
if(table.Name! Command)
{
SetTableConnectionInfo(table,databaseName,serverName,userName,password);
}
}

foreach(report.ReportDefinition.ReportObjects中的ReportObject obj)
{
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(表表,字符串databaseName,字符串serverName,字符串userName,字符串密码)
{
// Get ConnectionInfo对象。
var logOnInfo = table.LogOnInfo;
var connectionInfo = logOnInfo.ConnectionInfo;

//设置连接参数。
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;
}


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?

Here's the code

    private void MainReport_Load(object sender, EventArgs e)
    {
        var constr = string.Empty;
        constr = Application.StartupPath;
        if (Generate.bForProjects)
            constr = Path.Combine(constr, @"Reports\Projects.rpt");
        else
            constr = Path.Combine(constr, @"Reports\Other.rpt");

        var myConInfo = new CrystalDecisions.Shared.TableLogOnInfo();
        reportDocument1.Load(constr);
        myConInfo.ConnectionInfo.DatabaseName = "ProjectData.mdb";
        myConInfo.ConnectionInfo.ServerName = Application.StartupPath + @"\Data\ProjectData.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

And, when this comes up, I don't enter anything! That's right! I just click finish and it loads the report perfectly! So, if it doesn't needs anything, why the hel* is it asking me for a login?

解决方案

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.

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

这篇关于水晶报表,为什么它要求数据库登录,即使我提供了详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆