问题描述
我怎样才能更改数据源(数据库服务器,用户名,密码),一个水晶报表使用在运行时,晶体服务器中运行?
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中托管在服务器A,用户A,passwordA)报告。我想安排报告使用不同的数据源(SQL Server 2005的托管服务器B上,用户B,passwordB)从我写C#的客户端运行。
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#中客户机可以安排报告使用由晶体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
推荐答案
我有同样的问题,我在那里有一个具有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 Services的Crystal服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!