Post Author: BlueStallion
CA Forum: .NET
I am attempting to make a Crystal Reports viewer to display reports external to the viewer. The viewer is to display reports for a seperate application I'm writing. I want to be able to call the viewer and send it a parameter list with the database location, username, password, report file name and location, and then some other parameters specific to the report. I have the viewer working on my development machine when I use the MySQL database local to the development machine. However, when I log in to a MySQL database on a remote server the reports displayed are still from the database on the development machine. I send the viewer the IP to the other machine along with the username and password for the server machine, but I still get reports based on the development machine. I am using C# and Visual Studio 2005 to develop the viewer. What I would like to know is how to get the C# program to pass the server IP, username and password to the report so that it will access the server, and not the development machine. The applications will be deployed to other machines and when the user logs into my application it is logging into MySQL on whatever machine they are using; it could be local, or it could be remote. So I pass the login info to the viewer to pass to the report so it will know where to find its data. The following is the C# code that I have so far. This code is based on "Crystal Reports For Visual Studio 2005 Walkthroughs" which was downloaded from the Crystal Reports website. Unfortunately the walkthroughs are based on MS SQL Server and not MySQL. I forgot to mention: I want to use SQL authentication and do not want to use ODBC and DSN, as the applications will be deployed to other machines. Thanks for your help. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; using System.Collections; namespace CRViewer { public partial class Form1 : Form { //private const string PARAMETER_FIELD_NAME = "City"; public Form1() { InitializeComponent(); } private void ConfigureCrystalReports() { String[] arguments = Environment.GetCommandLineArgs(); if (arguments.GetLength(0) < 6) { MessageBox.Show("Usage: CRViewer server database username password reportname"); Application.Exit(); } //for (int i = 0; i < arguments.GetLength(0); i++) // MessageBox.Show(arguments[i]); ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.ServerName = arguments[1]; // server location connectionInfo.DatabaseName = arguments[2]; // database name connectionInfo.UserID = arguments[3]; // user name connectionInfo.Password = arguments[4]; // password // 5 report name.rpt // 6 parameter list // 1 - 1 string // 2 - 2 strings // 3 - 1 int // 7 Report Number // 8 Parameter 1 // 9 Parameter 2 string selectFormula = ""; if (arguments.GetLength(0) > 6) { if (arguments[6] == "1") { } else if (arguments[6] == "2") { if ((arguments[7] == "1") || (arguments[7] == "2") ||(arguments[7] == "3") ||(arguments[7] == "4") ||(arguments[7] == "9")) selectFormula = "{library.Category} = \"" + arguments[8] + "\" AND {library.AccessionNumber} >= \"" + arguments[9] + "\""; else selectFormula = "{library.Category} = \"" + arguments[8] + "\" AND {library.AccessionNumber} = \"" + arguments[9] + "\""; crystalReportViewer.SelectionFormula = selectFormula; } else if (arguments[6] == "3") { } } string reportPath = arguments[5]; crystalReportViewer.ReportSource = reportPath; SetDBLogonForReport(connectionInfo); } private void Form1_Load(object sender, EventArgs e) { ConfigureCrystalReports(); } private void SetDBLogonForReport(ConnectionInfo connectionInfo) { TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo; foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos) { tableLogOnInfo.ConnectionInfo = connectionInfo; } } } }