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
Updating the ODBC within a crystal report file.
We are using ODBC with MSSQL, we couldn't find how to update the ODBC within the crystal files within a C sharp project.
With the example provided here we were able to find the way to update the ODBC within MSSQL, and it is as simple as this:
Cursor.Current = Cursors.WaitCursor;
CrystalDecisions.Windows.Forms.CrystalReportViewer CR_Viewer;
CR_Viewer = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
this.Controls.Add(CR_Viewer);
ConnectionInfo connInfo = new ConnectionInfo();
connInfo.ServerName = "YOUR ODBC NAME";
TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();
tableLogOnInfo.ConnectionInfo = connInfo;
//THIS IS A CRYSTAL RPT FILE DIFINE AS A CLASS
Facturation_Nord_Ouest.Reports.Facture_Français CrystalReportFr;
CrystalReportFr = new Facturation_Nord_Ouest.Reports.Facture_Français();
for (int i = 0; i < CrystalReportFr.Database.Tables.Count; i++)
{
CrystalReportFr.Database.Tables[i].ApplyLogOnInfo(tableLogOnInfo);
}
CR_Viewer.ReportSource = CrystalReportFr;
CR_Viewer.ActiveViewIndex = 0;
CR_Viewer.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
CR_Viewer.Dock = System.Windows.Forms.DockStyle.Fill;
CR_Viewer.Location = new System.Drawing.Point(0, 0);
CR_Viewer.Size = new System.Drawing.Size(545, 379);
CR_Viewer.TabIndex = 0;
CR_Viewer.Name = "Invoice";
CR_Viewer.Zoom(100);
CR_Viewer.Show();
Cursor.Current = Cursors.Default;
With this the ODBC in the crystal file is automaticaly updated.