2005-09-28

 

.NET 2003 (C#) Connect to RAS Server 9

.NET 2003 (C#) Connect to RAS Server 9


Architecture:
Web Server + RAS SDK------------> RAS Server

Web Server:
1. Install “IIS” and “ .NET Framework V1.1”
2. Install “Crystal Reports 9” OR install “Report Application SDK 9” only, the SDK can be found in “Crystal Enterprise Report Application Server 9”. (The RAS Server is optional).
3. Create Virtual Directory in IIS Admin for running the .NET application.
4. File “CrystalDecisions.VSDesigner.dll” MUST exist in /bin directory. (A sub folder user Virtual Directory. This file can be found in directory “C:\Program Files\Crystal Decisions\Crystal Reports 9\” if “Crystal Reports 9” is installed.)

Note: For development, “Crystal Reports 9” must be installed. In Microsoft Visual Studio .NET 2003 environment, following resources are needed for reference. (CrystalDecisions.VSDesigner should be added manually from directory “C:\Program Files\Crystal Decisions\Crystal Reports 9\”):
CrystalDecisions.Enterprise.Framework
CrystalDecisions.Enterprise.InfoStore
CrystalDecisions.Enterprise.Report
CrystalDecisions.ReportAppServer.ClientDoc
CrystalDecisions.ReportAppServer.Controllers
CrystalDecisions.ReportAppServer.DataDefModel
CrystalDecisions.ReportSource
CrystalDecisions.Shared
CrystalDecisions.VSDesigner
CrystalDecisions.Web

Sample Code in C# to connect to RAS Server: (RAS Server IP is 10.18.0.200 and file “odbc_customer_params.rpt” is located in RAS Server’s Report Directory)
ReportClientDocument m_crReportDocument = new ReportClientDocument();
m_crReportDocument.ReportAppServer = "10.18.0.200";
object path = "odbc_customer_params.rpt";
m_crReportDocument.Open(ref path, 1);
// Parameters can be set by calling
// m_crReportDocument.DataDefController.ParameterFieldController.SetCurrentValues
CrystalReportViewer1.ReportSource = m_crReportDocument;

Report Application Server: (RAS Server)

1.Install “Report Application Server (RAS) 9”
The RAS 9 can be found in “Crystal Enterprise Report Application Server 9”. (The SDK is optional)

2. Report Directory Configuration
2.1 Click “Start à Programs à Crystal Enterprise 9 à Tools à RAS Configuration Manager”
2.2 Input the directory to store report files in “Report Directory” text field. The default value is “C:\Program Files\Crystal Decisions\Report Application Server 9\Reports’. Click OK
2.3 Restart the “Report Application Server” service. Click “Start à Run”, type cmd in Open field, then click OK to open Command Prompt. In Command Prompt, type net stop "Report Application Server" && net start "Report Application Server" to restart the service

3. Copy report files to Report Directory

4. Create System Data Source (located in Administrative Tools à Data Sources (ODBC) à System DSN) if need.


Full Sample Code in C# to connect RAS Server:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.VSDesigner;
using CrystalDecisions.Enterprise;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Shared;
using CrystalDecisions.Web;

namespace myRpt
{
public class WebForm1 : System.Web.UI.Page
{
protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;

public void PassParameter(ReportClientDocument doc,string report_name,
string param_name,object param_value)
{
// create parameter discrete value
ParameterFieldDiscreteValue param_val = new ParameterFieldDiscreteValue();
// set parameter value
param_val.Value = param_value;
// create parameter value collection
Values vals = new ValuesClass();
// add parameter value to this collection
vals.Add(param_val);
// set current value
doc.DataDefController.ParameterFieldController.SetCurrentValues(report_name, param_name, vals);
}

// identical to method above except this method takes index of the parameter instead of name
public void PassParameter(ReportClientDocument doc,string report_name,
int param_index,object param_value)
{
PassParameter(doc, report_name,
doc.DataDefinition.ParameterFields[param_index].Name, param_value);
}
private void Page_Load(object sender, System.EventArgs e)
{
ReportClientDocument m_crReportDocument = new ReportClientDocument();

// set RAS server location
m_crReportDocument.ReportAppServer = "10.18.0.200";

// open a report
// copy this report to "Report Directory" in RAS Configuration Manager
object path = "odbc_customer_params.rpt";
m_crReportDocument.Open(ref path, 1);

// in the report odbc_customer_params.rpt, there are two parameters: Country and Sales
// pass 'USA' and 5000 to each parameters
// 2nd parameter value is name of the report. Pass empty for main report. If you had a parameter in
// a subreport, you would pass this subreport name here.
PassParameter(m_crReportDocument, "", 0, "USA");
PassParameter(m_crReportDocument, "", 1, 5000);

// view the report
CrystalReportViewer1.ReportSource = m_crReportDocument;
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}


This page is powered by Blogger. Isn't yours?