动态设置Crystal报表仍然要求db登录 [英] Dynamically set Crystal Report still asks for db login

查看:364
本文介绍了动态设置Crystal报表仍然要求db登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的 MVC 应用程序中部署 Crystal Reports 为了充分利用Crystal报表查看器,我必须使用 webform ,这在我的开发环境中工作相当好。



应用程序将部署在用户的服务器上,并连接到他们的个人dbs。这意味着我在设计报表或应用程序时没有最终的连接信息。



我可以使用他们在web.config文件中的条目成功连接,加载a DataTable 与报告信息,并将其传递到报告。但是,报告仍在请求数据库凭据。该报告设置为连接到我的数据库,因此它要求我的凭据,如果没有他们将不会继续。但是,最终报告显示了他们的数据库中的正确信息。



我不知道是否需要更改报告中的内容,或者后面的代码。这是我如何设置报告 ReportSource 现在:

  Page_Load(object sender,EventArgs e)
{
string strReportName = System.Web.HttpContext.Current.Session [ReportName]。ToString();
try
{
ReportDocument rd = new ReportDocument();
string strRptPath = Server.MapPath(〜/)+Rpts //+ strReportName;
rd.Load(strRptPath);

SqlParameter [] sqlParams = {};
DataTable testDt = DBHelper.GetTable(rptInvtDuplDesc,sqlParams);
rd.DataSourceConnections.Clear();
rd.SetDataSource(testDt);
CrystalReportViewer1.ReportSource = rd;
}
else
{
Response.Write(< H2>找不到任何内容;找不到报告名< / H2>);
}
}

如何防止报告要求原始



如果我将登录信息传递给我的数据库这:

  rd.SetDatabaseLogon(username,password); 

我没有再次获得db登录。凭据必须是用于创建报告的数据库,但显示的结果来自上面方法中填充的 DataTable 。如果它有当前数据库需要的数据,为什么需要连接到原始数据库?



EDIT2: >

我有2个数据源用于此报告。一个是来自db的表,另一个是来自存储过程的结果。

解决方案

您必须为每个 datasouce



理想情况下,报告将有一个数据源。如果这不可能,您需要提供每个的凭据或每个的数据。



如果您想提供数据,这样的效果很好:

  rd.Database.Tables [0] .SetDataSource(testDt); 
rd.Database.Tables [1] .SetDataSource(micssys);

否则,类似这样的东西将允许报表直接访问每个 datasource

  rd.SetDatabaseLogon(username,password}); 


I am trying to deploy Crystal Reports in my MVC application. To get full use of the Crystal Report Viewer, I have to use a webform, which is working fairly well in my dev environment.

The application will be deployed on the user's servers and connect to their personal dbs. This means I do not have the final connection information when designing the report or the application.

I am able to successfully connect using their entries in the web.config file, load a DataTable with the report information, and pass it to the report. However, the report is still asking for the db credentials. The report is set to connect to my db, so it asks for my credentials and will not proceed without them. However, the final report shows the correct info from their db.

I am not sure if I need to change something in the report, or in the code behind. This is how I am setting the report ReportSource now:

protected void Page_Load(object sender, EventArgs e)
{
    string strReportName = System.Web.HttpContext.Current.Session["ReportName"].ToString();
    try
    {
        ReportDocument rd = new ReportDocument();
        string strRptPath = Server.MapPath("~/") + "Rpts//" + strReportName;
        rd.Load(strRptPath);

        SqlParameter[] sqlParams = {};
        DataTable testDt = DBHelper.GetTable("rptInvtDuplDesc", sqlParams);
        rd.DataSourceConnections.Clear();
        rd.SetDataSource(testDt);
        CrystalReportViewer1.ReportSource = rd;
    }
    else
    {
        Response.Write("<H2>Nothing Found; No Report name found</H2>");
    }
}

How do I prevent the report from asking for the original credentials?

EDIT:

If I pass the login to my db like this:

rd.SetDatabaseLogon("username", "password");

I do not get the db login again. The credentials have to be for the db used to create the report, but the displayed results are from the DataTable populated in the method above. If it has the data it needs from the current db, why does it need to connect to the original db?

EDIT2:

I have 2 data sources for this report. One is a table from the db and the other is the result from a stored procedure. I have now learned that is the cause of the extra login.

解决方案

You have to provide credentials for each datasouce in the report.

Ideally, the report will have a single datasource. If this is not possible, you need to provide credentials for each, or data for each.

Something like this works well if you want to provide the data:

rd.Database.Tables[0].SetDataSource(testDt);
rd.Database.Tables[1].SetDataSource(micssys);

Otherwise, something like this will allow the report to access the db directly for each datasource:

rd.SetDatabaseLogon("username","password}");

这篇关于动态设置Crystal报表仍然要求db登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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