Programmatically set the datasource for a Crystal Report on a Crystal Server via Crystal Web Services(通过 Crystal Web 服务以编程方式为 Crystal Server 上的 Crystal Report 设置数据源)
问题描述
如何更改 Crystal 报表在运行时使用的、在 Crystal 服务器中运行的数据源(数据库服务器、用户名、密码)?
How can I change the data source (database server, username, password) that a Crystal report uses at runtime, running within a crystal server?
我有一个水晶服务器并上传了具有一组数据源的报告(SQL Server 2005 托管在 SERVER A、userA、passwordA 上).我想安排报告使用与我编写的 c# 客户端不同的数据源(托管在 SERVER B、userB、passwordB 上的 SQL Server 2005)运行.
I have a crystal server and have uploaded reports that have a set datasource (SQL Server 2005 hosted on SERVER A, userA, passwordA). I would like to schedule reports to run using a different datasource (SQL Server 2005 hosted on SERVER B, userB, passwordB) from the c# client I've written.
c# 客户端可以使用由 Crystal Web 服务提供的对象来安排报表在服务器内运行.我一直在使用以下 3 个对象:
The c# client can schedule reports to run within the server using objects provided by the crystal webservices. I've been using the following 3 objects:
BIPlatform
InfoObject
CrystalReport
可以找到有关这些对象的文档 这里
Documentation on these objects can be found HERE
推荐答案
1/30/2018 - 只是想补充一下,您将需要 CrystalDecisions.ReportAppServer.DataDefModel dll
1/30/2018 -Just wanted to add that you will need the CrystalDecisions.ReportAppServer.DataDefModel dll
我遇到了同样的问题,我有一个具有 MSAccess 数据库连接的报告,我需要将其更改为 SQLServer,花了 2 天时间才弄清楚:
I had the same problem, where i have a report that has MSAccess database connection and i needed to change that to SQLServer, it took 2 days to figure this out:
reportDocument = new ReportDocument();
reportDocument.Load(reportFileName);
TableLogOnInfo tableLogOnInfo = ReportClass.GetSQLTableLogOnInfo(connectionProperties.DatabaseSource, connectionProperties.DatabaseName, connectionProperties.UserName, connectionProperties.Password);
for (int i = 0; i < reportDocument.Database.Tables.Count; i++)
{
Table table = reportDocument.Database.Tables[i];
table.ApplyLogOnInfo(tableLogOnInfo);
}
public static ConnectionInfo GetConnectionInfo(string serverName, string databaseName, string userID, string password)
{
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = serverName;
connectionInfo.DatabaseName = databaseName;
connectionInfo.UserID = userID;
connectionInfo.Password = password;
return connectionInfo;
}
public static TableLogOnInfo GetSQLTableLogOnInfo(string serverName, string databaseName, string userID, string password)
{
CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag connectionAttributes = new CrystalDecisions.ReportAppServer.DataDefModel.PropertyBag();
connectionAttributes.EnsureCapacity(11);
connectionAttributes.Add("Connect Timeout", "15");
connectionAttributes.Add("Data Source", serverName);
connectionAttributes.Add("General Timeout", "0");
connectionAttributes.Add("Initial Catalog", databaseName);
connectionAttributes.Add("Integrated Security", false);
connectionAttributes.Add("Locale Identifier", "1033");
connectionAttributes.Add("OLE DB Services", "-5");
connectionAttributes.Add("Provider", "SQLOLEDB");
connectionAttributes.Add("Tag with column collation when possible", "0");
connectionAttributes.Add("Use DSN Default Properties", false);
connectionAttributes.Add("Use Encryption for Data", "0");
DbConnectionAttributes attributes = new DbConnectionAttributes();
attributes.Collection.Add(new NameValuePair2("Database DLL", "crdb_ado.dll"));
attributes.Collection.Add(new NameValuePair2("QE_DatabaseName", databaseName));
attributes.Collection.Add(new NameValuePair2("QE_DatabaseType", "OLE DB (ADO)"));
attributes.Collection.Add(new NameValuePair2("QE_LogonProperties", connectionAttributes));
attributes.Collection.Add(new NameValuePair2("QE_ServerDescription", serverName));
attributes.Collection.Add(new NameValuePair2("SSO Enabled", false));
ConnectionInfo connectionInfo = ReportClass.GetConnectionInfo(serverName, databaseName, userID, password);
connectionInfo.Attributes = attributes;
connectionInfo.Type = ConnectionInfoType.SQL;
TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();
tableLogOnInfo.ConnectionInfo = connectionInfo;
return tableLogOnInfo;
}
这篇关于通过 Crystal Web 服务以编程方式为 Crystal Server 上的 Crystal Report 设置数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 Crystal Web 服务以编程方式为 Crystal Server 上的 Crystal Report 设置数据源
基础教程推荐
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01