How do I change a Crystal Report's ODBC database connection at runtime?

前端 未结 6 2042
暗喜
暗喜 2020-11-30 10:35

I have a report made with Crystal Reports 2008 that I need to deploy a production system which means that I need to be able to change the database connection at runtime. Th

6条回答
  •  执笔经年
    2020-11-30 11:13

    First of all thank you for this information!!!

    I'm using MySQL/C#/Crystal Reports. After setting up the ODBC/DSN something as simple as this worked for me.

    using CrystalDecisions.CrystalReports.Engine;
    
    using CrystalDecisions.Shared;
    
    using MySql.Data.MySqlClient;
    
    .
    .
    .
    
    ConnectionInfo connInfo = new ConnectionInfo();
    
    connInfo.ServerName = "Driver={MySQL ODBC 3.51 Driver};DSN=MyODBCDatasourceName";
    
    TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();
    
    tableLogOnInfo.ConnectionInfo = connInfo;
    
    // rpt is my Crystal Reports ReportDocument
    
    // Apply the schema name to the table's location
    
    foreach (Table table in rpt.Database.Tables)
    
    {
    
        table.ApplyLogOnInfo(tableLogOnInfo);
    
        table.Location = table.Location;
    
    }
    

提交回复
热议问题