可能没有设置登陆信息吧!/*********************************************File Name: csharp_win_oraclelogoninfo.sln Created: September 9, 2003 Author ID: HIT Purpose: This C# sample Windows application demonstrates how to provide Logon Information to an Oracle database at runtime. ********************************************/using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; namespace csharp_win_oraclelogoninfo { /// <summary> /// Summary description for Form1. /// </summary> public class Form1 : System.Windows.Forms.Form { private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; //CR Variables OracleReport crReportDocument; Database crDatabase; Tables crTables; TableLogOnInfo crTableLogOnInfo; ConnectionInfo crConnectionInfo; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); //Create an instance of the strongly-typed report object crReportDocument = new OracleReport(); //Set the crConnectionInfo with the current values stored in the report crConnectionInfo = crReportDocument.Database.Tables[0].LogOnInfo.ConnectionInfo; /* Populate the ConnectionInfo Objects Properties with the appropriate values for the ServerName, User ID, Password and DatabaseName. However, since Oracle works on Schemas, Crystal Reports does not recognize or store a DatabaseName. Therefore, the DatabaseName property must be set to a BLANK string. */ crConnectionInfo.DatabaseName = ""; crConnectionInfo.ServerName = "Your Server Name"; crConnectionInfo.UserID = "Your User ID"; crConnectionInfo.Password = "Your Password"; //Set the CrDatabase Object to the Report's Database crDatabase = crReportDocument.Database; //Set the CrTables object to the Tables collection of the Report's dDtabase crTables = crDatabase.Tables; //Loop through each Table object in the Tables collection and apply the logon info //specified ealier. Note this sample only has one table so the loop will only execute once foreach (Table crTable in crTables) { crTableLogOnInfo = crTable.LogOnInfo; crTableLogOnInfo.ConnectionInfo = crConnectionInfo; crTable.ApplyLogOnInfo (crTableLogOnInfo); // if you wish to change the schema name as well, you will need to set Location property as follows: // crTable.Location = "<new schema name>." + crTable.Name; } //Set the ReportSource of the CrystalReportViewer to the strongly typed Report included in the project crystalReportViewer1.ReportSource = 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.Forms.CrystalReportViewer(); this.SuspendLayout(); // // crystalReportViewer1 // this.crystalReportViewer1.ActiveViewIndex = -1; this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill; this.crystalReportViewer1.Name = "crystalReportViewer1"; this.crystalReportViewer1.ReportSource = null; this.crystalReportViewer1.Size = new System.Drawing.Size(784, 565); this.crystalReportViewer1.TabIndex = 0; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(784, 565); this.Controls.AddRange(new System.Windows.Forms.Control[] { 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()); } } }
Created: September 9, 2003
Author ID: HIT
Purpose: This C# sample Windows application
demonstrates how to provide Logon Information to
an Oracle database at runtime.
********************************************/using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace csharp_win_oraclelogoninfo
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; //CR Variables
OracleReport crReportDocument;
Database crDatabase;
Tables crTables;
TableLogOnInfo crTableLogOnInfo;
ConnectionInfo crConnectionInfo;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent(); //Create an instance of the strongly-typed report object
crReportDocument = new OracleReport(); //Set the crConnectionInfo with the current values stored in the report
crConnectionInfo = crReportDocument.Database.Tables[0].LogOnInfo.ConnectionInfo; /* Populate the ConnectionInfo Objects Properties with the appropriate values for
the ServerName, User ID, Password and DatabaseName. However, since Oracle
works on Schemas, Crystal Reports does not recognize or store a DatabaseName.
Therefore, the DatabaseName property must be set to a BLANK string. */
crConnectionInfo.DatabaseName = "";
crConnectionInfo.ServerName = "Your Server Name";
crConnectionInfo.UserID = "Your User ID";
crConnectionInfo.Password = "Your Password"; //Set the CrDatabase Object to the Report's Database
crDatabase = crReportDocument.Database; //Set the CrTables object to the Tables collection of the Report's dDtabase
crTables = crDatabase.Tables; //Loop through each Table object in the Tables collection and apply the logon info
//specified ealier. Note this sample only has one table so the loop will only execute once
foreach (Table crTable in crTables)
{
crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo (crTableLogOnInfo); // if you wish to change the schema name as well, you will need to set Location property as follows:
// crTable.Location = "<new schema name>." + crTable.Name;
} //Set the ReportSource of the CrystalReportViewer to the strongly typed Report included in the project
crystalReportViewer1.ReportSource = 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.Forms.CrystalReportViewer();
this.SuspendLayout();
//
// crystalReportViewer1
//
this.crystalReportViewer1.ActiveViewIndex = -1;
this.crystalReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.crystalReportViewer1.Name = "crystalReportViewer1";
this.crystalReportViewer1.ReportSource = null;
this.crystalReportViewer1.Size = new System.Drawing.Size(784, 565);
this.crystalReportViewer1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(784, 565);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
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());
}
}
}