We help IT Professionals succeed at work.

Rendering timeout when calling report through C# code

8,600 Views
Last Modified: 2013-11-26
The timeout on our SQL 2005 Reporting Services is set to 1800 seconds.  When I call the report through code by making an instance of the reporting service on my web page, it times out after like 45 seconds.

The code being used to render the report is:
    protected void BtnProcessOnDemand_Click(object sender, EventArgs e)
    {
        this.LblError.Visible = false;
        this.LblError.Text = "";
        //initialize variables
        String SITEID = "%";
        String DIVID = "%";
        String BENGROUPID = "%";
        DateTime PREMDATE = System.DateTime.Now;
        if (TxtRptPremDate.Text.Length > 0)
        {
            PREMDATE = Convert.ToDateTime(TxtRptPremDate.Text.ToString());
        }
        else
        {
            LblError.Text = "Please input a premium date.";
            LblError.Visible = true;
            return;
        }

        if (DdlSite.SelectedIndex != 0)
        {
            SITEID = DdlSite.SelectedValue;
            if (DdlDivision.SelectedIndex != 0)
            {
                DIVID = DdlDivision.SelectedValue;
                if (DdlBenGroup.SelectedIndex != 0)
                {
                    BENGROUPID = DdlBenGroup.SelectedValue;
                }
            }
        }

        //if (((Button)sender).CommandName.ToString() != LblHidden.Text)
        //{
            String error = "";
            ReportExecutionService RE = new ReportExecutionService();
            RE.Credentials = new System.Net.NetworkCredential("Username", "Password", "Domain");

            RE.Url = "http://report.ntlbenefit.com/reportserver/reportexecution2005.asmx?wsdl";

            // Render arguments
            DataSet pathdir = SC.get_path();

            DataSet report = SC.get_reportinfo(DdlReportsOD.SelectedValue.ToString());
            byte[] result = null;
            string reportPath = "/" + pathdir.Tables[0].Rows[0]["path_folder"].ToString() + "/" + report.Tables[0].Rows[0]["rpt_link"].ToString();
            string format = DdlFormat.SelectedValue.ToString();
            string historyID = null;
            string devInfo = @"<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>";
            // Prepare report parameter.
            ParameterValue[] parameters = new ParameterValue[5];
            parameters[0] = new ParameterValue();
            parameters[0].Name = "SITEID";
            parameters[0].Value = SITEID;
            parameters[1] = new ParameterValue();
            parameters[1].Name = "DIVID";
            parameters[1].Value = DIVID;
            parameters[2] = new ParameterValue();
            parameters[2].Name = "BENGROUPID";
            parameters[2].Value = BENGROUPID;
            parameters[3] = new ParameterValue();
            parameters[3].Name = "PREMDATE";
            parameters[3].Value = PREMDATE.ToString();
            parameters[4] = new ParameterValue();
            parameters[4].Name = "ADMINID";
            parameters[4].Value = Session["AdminID"].ToString();
            //LblError.Text = reportPath;
            //LblError.Visible = true;
            //return;
            DataSourceCredentials[] credentials = null;
            string showHideToggle = null;
            string encoding;
            string mimeType;
            string extension;
            string actualextension;
            actualextension = DdlFormat.SelectedValue.ToString();
            Warning[] warnings = null;
            ParameterValue[] reportHistoryParameters = null;
            string[] streamIDs = null;

            ExecutionInfo execInfo = new ExecutionInfo();
            ExecutionHeader execHeader = new ExecutionHeader();

            RE.ExecutionHeaderValue = execHeader;
            try
            {
                execInfo = RE.LoadReport(reportPath, historyID);
            }
            catch (Exception eload)
            {
                this.LblError.Text = "The requested report is not available, please check back soon.";
                this.LblError.Visible = true;
                return;
            }
            RE.SetExecutionParameters(parameters, "en-us");
            String SessionId = RE.ExecutionHeaderValue.ExecutionID;

            try
            {
                result = RE.Render(format, devInfo, out extension, out encoding, out mimeType, out warnings, out streamIDs);
            }
            catch (SoapException soape)
            {
                error = soape.ToString() + "</ br>";
            }
            // Write the contents of the report to an MHTML file.
       
           
            try
            {
                String guid = Guid.NewGuid().ToString();
                FileStream stream = File.Create(Server.MapPath("~/Temp/" + guid + "." + actualextension), result.Length);
                stream.Write(result, 0, result.Length);
                stream.Close();
                LblHidden.Text = report.Tables[0].Rows[0]["rpt_link"].ToString();
                //this.PnlConfirm.Visible = true;
                LblDisplay.Text = "<iframe width='100%' src='" + "../Temp/" + guid + "." + actualextension + "' height='1200px'></iframe>";
            }
            catch (Exception ex)
            {
                error = ex.ToString() + "</ br>";
            }

            if (error.Length > 0)
            {
                this.LblError.Text = error.ToString();
                this.LblError.Visible = true;
            }
        //}
    }

When developing a sql statement in my webservice I can set how long it takes to time out the connection.  Is there a similar function when rendering from a page.  Some of these reports take 10 to 15 minutes to generate.  

Any help would be greatly appreciated.
Comment
Watch Question

Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
That's what I'm asking, how do you set the timeout with the rendering method?
ReportExecutionService rs = new ReportExecutionService();
rs.Timeout = System.Threading.Timeout.Infinite;

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.