简体   繁体   English

水晶报表和登录问题

[英]Crystal Reports and Login issue

I need some help. 我需要协助。

Actually, I've read about this problem, and I thought that I've resolved it, but it keeps bothering me. 实际上,我已经读过这个问题,并且我认为我已经解决了它,但是它一直困扰着我。

It's about different logins at developing and production enviroment. 它与开发和生产环境中的不同登录名有关。

This was supposed to be solution (EF and SQL Server): 这应该是解决方案(EF和SQL Server):

SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder((model.Connection as EntityConnection).StoreConnection.ConnectionString);

ConnectionInfo ci = new ConnectionInfo();

ci.ServerName = builder.DataSource;
ci.DatabaseName = builder.InitialCatalog;
ci.UserID = builder.UserID;
ci.Password = builder.Password;

report.SetDatabaseLogon(ci.UserID, ci.Password, builder.DataSource, ci.DatabaseName);

foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in report.Database.Tables)
{
    TableLogOnInfo logon = tbl.LogOnInfo;
    logon.ConnectionInfo = ci;
    tbl.ApplyLogOnInfo(logon);
}

I extract login information from Entity Connection and apply it to all the tables in report. 我从实体连接中提取登录信息,并将其应用于报告中的所有表。 That should do the trick. 这应该够了吧。 I added SetDatabaseLogon() only to be sure, but that's not required. 我只是为了确定才添加了SetDatabaseLogon(),但这不是必需的。

Now, when I run report in production enviroment, report pops up a Database login screen showing CORRECT server name (production server), NOTHING next to database (that is my concern), proper username, and no password, asking to type in login information. 现在,当我在生产环境中运行报告时,报告会弹出一个数据库登录屏幕,显示正确的服务器名称(生产服务器),数据库旁边没有什么(这是我所关心的),正确的用户名和无密码,要求输入登录信息。

I type it in, but CR says "Login failed. Please try again". 我输入了它,但是CR说“登录失败。请重试”。 I mean WTF. 我的意思是WTF。 I use the very same credential to connect to database with Management Studio. 我使用相同的凭据通过Management Studio连接到数据库。

I am using WPF viewer, BTW. 我正在使用WPF查看器,顺便说一句。

I am really stuck here, I've done some debugging, and connection info gets all the right data, so it must be report who is the culprit, but what should I do? 我确实被困在这里,我已经进行了一些调试,并且连接信息会获取所有正确的数据,因此必须报告是谁是罪魁祸首,但是我该怎么办?

Any help would be appreciated. 任何帮助,将不胜感激。 I hope somebody has stumbled to a same problem before me. 我希望有人在我面前偶然发现了同样的问题。

Regards 问候

I had a problem with using "SetDatabaseLogon" 我在使用“ SetDatabaseLogon”时遇到问题

I changed by 我改变了

report.DataSourceConnections[0].SetConnection("Servername","InitialCatalog", "UserID", "Password");

I hope this will helpful to someone. 我希望这对某人有帮助。

Looking at the code on my Blog Post that does the same jobs, I can see a few differences: 查看我的Blog Post上执行相同工作的代码,我可以看到一些区别:

  • Set tbl.Location to itself (this might be re initializing something internally - it didn't work without it). tbl.Location设置tbl.Location自身(这可能是在内部重新初始化某些内容-没有它就无法工作)。
  • Put your code in a method that you can re-call to handle sub reports: 将您的代码放在可以重新调用以处理子报表的方法中:
  • My version never needs to call report.SetDatabaseLogon 我的版本不需要调用report.SetDatabaseLogon

Other than that they're basically identical. 除此之外,它们基本上是相同的。

Code: 码:

void SetConnection(ReportDocument rd, crConnectionInfo ci)
{

    foreach (CrystalDecisions.CrystalReports.Engine.Table tbl in rd.Database.Tables)
    {
        TableLogOnInfo logon = tbl.LogOnInfo;
        logon.ConnectionInfo = ci;
        tbl.ApplyLogOnInfo(logon);
        tbl.Location = tbl.Location;
    }
    if (!rd.IsSubReport) {
        foreach {ReportDocument sd in rd.SubReports) {
            SetConnection(sd,ci)
        }
    }
}

(Note: Just hand coded this, so check it before you use it). (注意:只需手工编码,所以在使用前请检查一下)。

This works on the VS2008 version of crystal reports (forget what it was called). 这适用于水晶报表的VS2008版本(忘记它的名称)。

EDIT: One other thing, in my connection initialization, there are a couple of extra properties set: 编辑:另一件事,在我的连接初始化中,设置了几个额外的属性:

ci.Type = ConnectionInfoType.SQL;
ci.IntegratedSecurity = false;

It was totally stupid problem, and i solved it by chance. 这完全是愚蠢的问题,我是偶然解决的。 Installation of Crystal Reports on my desktop computer was crooked or something, so whenever I edited something with database expert (add some tables, for example), it spoiled my report. 在我的台式计算机上安装Crystal Reports有点不对劲,因此每当我用数据库专家编辑某些内容(例如,添加一些表)时,都会破坏我的报告。 All I did is use "set database location" option on my laptop, and now my reports run flawlessly. 我所做的就是在笔记本电脑上使用“设置数据库位置”选项,现在我的报告可以完美运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM