1

如何将 System.Data.SqlClient.SqlConnection 转换为 CrystalDecisions.Shared.ConnectionInfo

有可能吗?请有人帮忙解决这个问题。

4

3 回答 3

0

根据MSDN for ConnectionInfo, ConnectionInfo 对象就是它所声明的,有关连接的信息。 SqlConnection用于建立与数据库的连接。

SqlConnection 具有创建 ConnectionInfo 对象所需的信息。具体来说, DataSourceDatabaseCredential

于 2012-10-05T00:50:59.567 回答
0

Why can't you create a new CrystalDecisions.Shared.ConnectionInfo object and set it's properties equal to the corresponding property on the SqlConnection?

于 2012-10-05T01:11:00.767 回答
0

发现自己处于类似情况,解决方案不是将sqlconnection本身转换为connectioninfo,而是使用连接字符串。以下使用 SqlConnectionStringBuilder 的代码就是这样做的:

ConnectionInfo connection = new ConnectionInfo();

string connectionString = ConfigurationManager.ConnectionStrings["_2Focus.Properties.Settings._2ServeConnection"].ConnectionString;
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(connectionString);
connection.ServerName = builder.DataSource;
connection.DatabaseName = builder.InitialCatalog;
connection.IntegratedSecurity = builder.IntegratedSecurity;
if (!builder.IntegratedSecurity)
{
    connection.Password = builder.Password;
    connection.UserID = builder.UserID;
}

Tables CrTables = report.Database.Tables 
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
    CrTable.LogOnInfo.ConnectionInfo = connection;
    CrTable.ApplyLogOnInfo(CrTable.LogOnInfo);
} 

这个问题太老了,操作没有很多点,所以可能不会被标记为答案。无论如何,我认为这是正确的做法。

于 2015-12-09T09:30:26.707 回答