dcass
asked on
.NET, C#, Windows App, Crystal Reports, SQL - asks for password - can't use - examples don't work
I am using .NET, C#, Windows App, Crystal Reports, SQL which is easy to create and runs but it asks the USER for the SQL password. I can't use it because I can't give the users the SQL password and from what I read there is no way to specify the password in Crystal, you have to do it in the C# program. I've tried about 10 examples I found on the internet, but none of them would compile, including the Microsoft example with ConnectionInfo. If you know what I'm talking about, it uses REPORT which doesn't exist and it doesn't tell where it came from (maybe I need a using statement, but I've tried every one that has anything to do with Crystal and it still didn't work). I'm a C# novice, so if you would rather send a VB example, feel free - I'll take anything that will get rid of the password inquiry. But I need the entire code, not just pieces like Microsoft does, so a full example would be great.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I found a way to make it work so I'm withdrawing the question:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CrystalDecisions.CrystalRe ports.Engi ne;
using CrystalDecisions.Shared;
namespace BlountReports
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private CrystalDecisions.Windows.F orms.Cryst alReportVi ewer crystalReportViewer1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont ainer components = null;
//CrystalReport1 crReportDocument;
TableLogOnInfos crTableLogonInfos;
TableLogOnInfo crTableLogonInfo;
ConnectionInfo crConnectionInfo;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//crReportDocument = new CrystalReport1();
crTableLogonInfos = new TableLogOnInfos();
crTableLogonInfo = new TableLogOnInfo();
crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerNam e = "ServerName";
crConnectionInfo.DatabaseN ame = "DBName";
crConnectionInfo.UserID = "sa";
crConnectionInfo.Password = "XXXX"
crTableLogonInfo.Connectio nInfo = crConnectionInfo;
crTableLogonInfo.TableName = "table name";
crTableLogonInfos.Add(crTa bleLogonIn fo);
crystalReportViewer1.LogOn Info = crTableLogonInfos;
//crystalReportViewer1.Rep ortSource = crReportDocument;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.crystalReportViewer1 = new CrystalDecisions.Windows.F orms.Cryst alReportVi ewer();
this.SuspendLayout();
//
// crystalReportViewer1
//
this.crystalReportViewer1. ActiveView Index = -1;
this.crystalReportViewer1. Location = new System.Drawing.Point(24, 24);
this.crystalReportViewer1. Name = "crystalReportViewer1";
this.crystalReportViewer1. ReportSour ce = "C:\\Visual Studio Projects\\Reports\\Labels. rpt";
this.crystalReportViewer1. Size = new System.Drawing.Size(600, 272);
this.crystalReportViewer1. TabIndex = 0;
this.crystalReportViewer1. Load += new System.EventHandler(this.c rystalRepo rtViewer1_ Load);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(680, 334);
this.Controls.AddRange(new System.Windows.Forms.Contr ol[] {
this.crystalReportViewer1} );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void crystalReportViewer1_Load( object sender, System.EventArgs e)
{
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CrystalDecisions.CrystalRe
using CrystalDecisions.Shared;
namespace BlountReports
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private CrystalDecisions.Windows.F
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Cont
//CrystalReport1 crReportDocument;
TableLogOnInfos crTableLogonInfos;
TableLogOnInfo crTableLogonInfo;
ConnectionInfo crConnectionInfo;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//crReportDocument = new CrystalReport1();
crTableLogonInfos = new TableLogOnInfos();
crTableLogonInfo = new TableLogOnInfo();
crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerNam
crConnectionInfo.DatabaseN
crConnectionInfo.UserID = "sa";
crConnectionInfo.Password = "XXXX"
crTableLogonInfo.Connectio
crTableLogonInfo.TableName
crTableLogonInfos.Add(crTa
crystalReportViewer1.LogOn
//crystalReportViewer1.Rep
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.crystalReportViewer1 = new CrystalDecisions.Windows.F
this.SuspendLayout();
//
// crystalReportViewer1
//
this.crystalReportViewer1.
this.crystalReportViewer1.
this.crystalReportViewer1.
this.crystalReportViewer1.
this.crystalReportViewer1.
this.crystalReportViewer1.
this.crystalReportViewer1.
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(680, 334);
this.Controls.AddRange(new
this.crystalReportViewer1}
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void crystalReportViewer1_Load(
{
}
}
}
ASKER
I solved it myself but would like to give TheAvenger 150 points for responding.
ASKER
I know I probably put the code in the wrong place, so here it is:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CrystalDecisions.CrystalRe
using CrystalDecisions.Shared;
namespace BlountReports
{
public class Form1 : System.Windows.Forms.Form
{
private CrystalDecisions.Windows.F
private System.ComponentModel.Cont
public Form1()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.crystalReportViewer1 = new CrystalDecisions.Windows.F
this.SuspendLayout();
this.crystalReportViewer1.
this.crystalReportViewer1.
this.crystalReportViewer1.
this.crystalReportViewer1.
this.crystalReportViewer1.
this.crystalReportViewer1.
this.crystalReportViewer1.
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(680, 334);
this.Controls.AddRange(new
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void crystalReportViewer1_Load(
{
}
private void FixDatabase (ReportDocument report, String un, String pass, String dbName, String serverName)
{
foreach (Table table in report.Database.Tables)
{
TableLogOnInfo logOnInfo = table.LogOnInfo;
if (logOnInfo != null)
{
logOnInfo.ConnectionInfo.U
logOnInfo.ConnectionInfo.P
logOnInfo.ConnectionInfo.D
logOnInfo.ConnectionInfo.S
table.ApplyLogOnInfo (logOnInfo);
}
}
foreach (ReportObject reportObject in report.ReportDefinition.Re
if (reportObject.Kind == ReportObjectKind.Subreport
FixDatabase (report.OpenSubreport (((SubreportObject)reportO
}
}
}