Skip to Content
0
Former Member
Feb 16, 2009 at 10:38 PM

How to set Command Timeout in Crystal report while calling from C# code

417 Views

I am using Crystal report XI R2. I am calling SQL server 2005 stored procedure as source in the report. I want the report should timeout from the website if the stored procedure doesn't return resultset after 5 minute. Could you please assist how should I chnage the below code to achieve that.

Code :

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using CrystalDecisions.CrystalReports.Design;

using CrystalDecisions.Shared;

using CrystalDecisions.Web;

using CrystalDecisions.CrystalReports.Engine;

namespace CrystalTest

{

public partial class _Default : System.Web.UI.Page

{

protected ReportDocument rd;

protected CrystalReportViewer Crv;

protected void Page_Load(object sender, EventArgs e)

{

rd = new ReportDocument();

rd.Load(Request.MapPath("FXRate.rpt"));

SetDBLogonForReport(GetCrvConnectionInfo(), rd);

ParameterFields crtParamFields;

ParameterDiscreteValue crtParamDiscreteValue1;

ParameterField crtParamField1;

ParameterDiscreteValue crtParamDiscreteValue2;

ParameterField crtParamField2;

ParameterDiscreteValue crtParamDiscreteValue3;

ParameterField crtParamField3;

ParameterDiscreteValue crtParamDiscreteValue4;

ParameterField crtParamField4;

ParameterDiscreteValue crtParamDiscreteValue5;

ParameterField crtParamField5;

ParameterDiscreteValue crtParamDiscreteValue6;

ParameterField crtParamField6;

crtParamFields = new ParameterFields();

crtParamDiscreteValue1 = new ParameterDiscreteValue();

crtParamField1 = new ParameterField();

crtParamDiscreteValue1.Value = "USD";

crtParamField1.ParameterFieldName = "@BaseCurrCode";

crtParamField1.CurrentValues.Add(crtParamDiscreteValue1);

crtParamFields.Add(crtParamField1);

crtParamDiscreteValue2 = new ParameterDiscreteValue();

crtParamField2 = new ParameterField();

crtParamDiscreteValue2.Value = "EUR";

crtParamField2.ParameterFieldName = "@CounterCurrCode";

crtParamField2.CurrentValues.Add(crtParamDiscreteValue2);

crtParamFields.Add(crtParamField2);

crtParamDiscreteValue3 = new ParameterDiscreteValue();

crtParamField3 = new ParameterField();

crtParamDiscreteValue3.Value = "2008-05-28 00:00:00";

crtParamField3.ParameterFieldName = "@FromDate";

crtParamField3.CurrentValues.Add(crtParamDiscreteValue3);

crtParamFields.Add(crtParamField3);

crtParamDiscreteValue4 = new ParameterDiscreteValue();

crtParamField4 = new ParameterField();

crtParamDiscreteValue4.Value = "2008-05-28 00:00:00";

crtParamField4.ParameterFieldName = "@ToDate";

crtParamField4.CurrentValues.Add(crtParamDiscreteValue4);

crtParamFields.Add(crtParamField4);

crtParamDiscreteValue5 = new ParameterDiscreteValue();

crtParamField5 = new ParameterField();

crtParamDiscreteValue5.Value = "ashok12";

crtParamField5.ParameterFieldName = "@CurrentUser";

crtParamField5.CurrentValues.Add(crtParamDiscreteValue5);

crtParamFields.Add(crtParamField5);

crtParamDiscreteValue6 = new ParameterDiscreteValue();

crtParamField6 = new ParameterField();

crtParamDiscreteValue6.Value = DateTime.Now.ToString("dd MMM yyyy hh:mm");

crtParamField6.ParameterFieldName = "@ClientTime";

crtParamField6.CurrentValues.Add(crtParamDiscreteValue6);

crtParamFields.Add(crtParamField6);

Crv.ParameterFieldInfo = crtParamFields;

Crv.DisplayGroupTree = false;

Crv.BestFitPage = true;

Crv.ReportSource = rd;

}

private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument reportDocument)

{

Tables tables = reportDocument.Database.Tables;

foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)

{

TableLogOnInfo tableLogonInfo = table.LogOnInfo;

tableLogonInfo.ConnectionInfo = connectionInfo;

table.ApplyLogOnInfo(tableLogonInfo);

}

}

public static CrystalDecisions.Shared.ConnectionInfo GetCrvConnectionInfo()

{

CrystalDecisions.Shared.ConnectionInfo con = new CrystalDecisions.Shared.ConnectionInfo();

con.ServerName = System.Configuration.ConfigurationSettings.AppSettings["conServer"].ToString();

con.DatabaseName = System.Configuration.ConfigurationSettings.AppSettings["conDatabase"].ToString();

con.UserID = System.Configuration.ConfigurationSettings.AppSettings["sesUser"].ToString();

con.Password = System.Configuration.ConfigurationSettings.AppSettings["sesPwd"].ToString();

return con;

}

private void Page_Unload(object sender, System.EventArgs e)

{

if (rd != null)

{

rd.Close();

rd.Dispose();

}

if (Crv != null)

{

Crv.HasCrystalLogo = false;

Crv.Dispose();

}

}

}

}