It seems that the connectionInfo.ServerName = "XXX"; property in my code is being ignored. No matter what I type in there, it keeps trying to use the ServerName that was used for the report creation. Unfortunately, that was my development server and now I need it to use my clients production server. It applies the user and pass correctly as I tried changing those values in the code and it reflected in the login prompt that eventually appears.
I'm fairly certain my code is right as I relied on the VS2005 walkthrough for a lot of it but I am also new to Crystal Reports. Any help would be appreciated.
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;
namespace Val_Report
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//Set up database and report path
ConfigureCrystalReports();
//Set Report Dates Initially at first of month to current date
//Get first day of month
DateTime firstDay = DateTime.Now;
DateTime FirstDayInMonth = new DateTime(firstDay.Year, firstDay.Month, 1);
string strStartDate = FirstDayInMonth.ToShortDateString();
//Set the orderStartDate TimePicker to value
orderStartDate.Value = FirstDayInMonth;
//Get current date
string strEndDate = DateTime.Now.ToShortDateString();
//Set the orderEndDate TimePicker to value
orderEndDate.Value = DateTime.Now;
//Set up my report parameters (date, etc)
setReportParameters(strStartDate, strEndDate);
}
private void ConfigureCrystalReports()
{
//Set up sql connection
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = "Database";
connectionInfo.DatabaseName = "db_name";
connectionInfo.UserID = "test";
connectionInfo.Password = "test";
connectionInfo.IntegratedSecurity = false;
//Set report path
string reportPath = Application.StartupPath + "\\" + "ValidationView.rpt";
crystalReportViewer.ReportSource = reportPath;
// Loop through main report and set connection info
SetDBLogonForReport(connectionInfo);
}
private void SetDBLogonForReport(ConnectionInfo connectionInfo)
{
TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;
foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
{
tableLogOnInfo.ConnectionInfo = connectionInfo;
}
}
private void crystalReportViewer_Load(object sender, EventArgs e)
{
}
private void setReportParameters(string strStartDate, string strEndDate)
{
// all the parameter fields will be added to this collection
ParameterFields paramFields = new ParameterFields();
// the parameter fields to be sent to the report
ParameterField pfStartDate = new ParameterField();
ParameterField pfEndDate = new ParameterField();
// setting the name of parameter fields with wich they will be recieved in report
pfStartDate.ParameterFieldName = "StartDate";
pfEndDate.ParameterFieldName = "EndDate";
// the above declared parameter fields accept values as discrete objects
// so declaring discrete objects
ParameterDiscreteValue dcStartDate = new ParameterDiscreteValue();
ParameterDiscreteValue dcEndDate = new ParameterDiscreteValue();
// setting the values of discrete objects
dcStartDate.Value = DateTime.Parse(strStartDate);
dcEndDate.Value = DateTime.Parse(strEndDate);
// now adding these discrete values to parameters
pfStartDate.CurrentValues.Add(dcStartDate);
pfEndDate.CurrentValues.Add(dcEndDate);
// now adding all these parameter fields to the parameter collection
paramFields.Add(pfStartDate);
paramFields.Add(pfEndDate);
/* Set the modified parameters collection back to the viewer so that
the new parameter information can be used for the report. */
crystalReportViewer.ParameterFieldInfo = paramFields;
}
private void redisplay_Click_1(object sender, EventArgs e)
{
// ConfigureCrystalReports();
string strStartDate = orderStartDate.Text;
string strEndDate = orderEndDate.Text;
string reportPath = Application.StartupPath + "\\" + "ValidationView.rpt";
crystalReportViewer.ReportSource = reportPath;
setReportParameters(strStartDate, strEndDate);
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form about = new Validation_Report.About();
about.ShowDialog();
}
}
}