简体   繁体   English

Crystal Report以Dataset作为数据源时显示数据库登录

[英]Crystal report shows database login when taking Dataset as datasource

In my project i use EF4, but the connection string of the EF Context are dynamically generated and not saved in any Configuration file, everything works fine... 在我的项目中,我使用EF4,但是EF上下文的连接字符串是动态生成的,并且未保存在任何配置文件中,一切正常...

When i want to use Crystal report to view my reports, I used Datasets that import data form the my Entities (linq), and than set the Datasets as Datasources to the reports Here Is A Tutorial 当我想用水晶报表来查看我的报告,我用导入数据形成我的实体(LINQ),而且比设定数据集作为数据源的数据集报道这里是一个教程

But at the moment of the display (in the CrystalReportViewer) a login prompt window pops up, asking for Login & Password (also the Server name and database name but the fields are disabled) 但是在显示的那一刻(在CrystalReportViewer中)会弹出一个登录提示窗口,询问登录名和密码(服务器名称和数据库名称,但字段已禁用)

图片

I Googled and i noticed that most of the solutions proposed concentrate around : Setting credentials in the code (like this) : 我在Google上搜索了一下,发现大多数建议的解决方案都集中在:在代码中设置凭据(像这样):

ConnectionInfo crconnectioninfo = new ConnectionInfo();
crconnectioninfo.ServerName = "localhost";
crconnectioninfo.DatabaseName = "dbclients";
crconnectioninfo.UserID = "ssssssss";
crconnectioninfo.Password = "xxxxxxx"; 

but here is how i create my report : 但是这是我创建报告的方式:

for (i = 0; i < 7; i++)
{
    DataRow dr = container.NewRow();
    dr = CreateRowFromMirrorRow(dr, i); //Methode that creates a Row
    container.Rows.Add(dr);
}

objRpt.SetDataSource(container.DefaultView);

// Binding the crystalReportViewer with our report object. 
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
crystalReportViewer1.Visible = true;

My questions are : 我的问题是:

  • Why do i have to pass any database credentials since there is no direct connection between the CrReport or the Dataset with the Database? 为什么在CrReport或数据集与数据库之间没有直接连接,为什么我必须传递任何数据库凭据?

  • How do i set the credential of a Dataset (or crystal report) using a ConnectionInfo object (in my case)? 如何使用ConnectionInfo对象(在我的情况下)设置数据集(或水晶报表)的凭据?

In my experience, when you have Crystal Reports asking for credentials when it's not supposed to, there's something wrong that appears unrelated on the surface. 以我的经验,当您让Crystal Reports在不应该提供的条件下要求提供凭据时,表面上似乎出现了不相关的错误。

I think you might be able to get it to work if you don't call Refresh on the viewer, but call refresh on the report itself instead: 我认为,如果您不在查看器上调用“ Refresh ”,而是在报表本身上调用“刷新”,则也许可以使其工作:

objRpt.SetDataSource(container.DefaultView);
objRpt.Refresh();

crystalReportViewer1.ReportSource = objRpt;
// Don't refresh viewer!
// If you have any report parameters, set them through the viewer here.

If for some reason, if you do need to set the connection for Crystal Report in the future, you can use this on the report before setting the report viewer's ReportSource : 如果出于某种原因,如果以后确实需要设置Crystal Report的连接,则可以在设置报表查看器的ReportSource之前在报表上使用此连接:

foreach (Table crTable in report.Database.Tables)
{
    TableLogOnInfo tableLogOnInfo = crTable.LogOnInfo;
    var connectionInfo = tableLogOnInfo.ConnectionInfo;

    // use connectionInfo to set database credentials

    crTable.ApplyLogOnInfo(tableLogOnInfo);
}

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

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