Dynamically set Crystal Report still asks for db login(动态设置水晶报表仍然要求数据库登录)
问题描述
我正在尝试在我的 MVC
应用程序中部署 Crystal Reports
.为了充分利用 Crystal Report Viewer,我必须使用 webform
,它在我的开发环境中运行良好.
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.
我能够使用他们在 web.config 文件中的条目成功连接,加载带有报告信息的 DataTable
,并将其传递给报告.但是,该报告仍然要求提供数据库凭据.该报告设置为连接到我的数据库,因此它会询问我的凭据并且没有它们就不会继续.但是,最终报告显示了他们数据库中的正确信息.
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.
我不确定是否需要更改报告中的某些内容,或者后面的代码.这就是我现在设置报告 ReportSource
的方式:
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?
如果我像这样将登录信息传递给我的数据库:
If I pass the login to my db like this:
rd.SetDatabaseLogon("username", "password");
我没有再次获得数据库登录.凭据必须是用于创建报告的数据库,但显示的结果来自上述方法中填充的 DataTable
.如果它从当前db有它需要的数据,为什么还要连接到原来的db?
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?
我有 2 个用于此报告的数据源.一个是数据库中的表,另一个是存储过程的结果.我现在知道这是额外登录的原因.
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.
推荐答案
您必须为报告中的每个 datasouce
提供凭据.
You have to provide credentials for each datasouce
in the report.
理想情况下,报告将有一个datasource
.如果这不可能,您需要为每个提供凭据,或为每个提供数据.
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);
否则,这样的事情将允许报告直接访问每个 datasource
的数据库:
Otherwise, something like this will allow the report to access the db directly for each datasource
:
rd.SetDatabaseLogon("username","password}");
这篇关于动态设置水晶报表仍然要求数据库登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:动态设置水晶报表仍然要求数据库登录
基础教程推荐
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- rabbitmq 的 REST API 2022-01-01