Avatar of national_fulfillment
national_fulfillmentFlag for United States of America

asked on 

C# time out exception when passing data to http response

I"m trying to send the user a pretty decent about of data could be about 200,000 records or more. WHen i run the selections it always times out. If i run smaller ones it works. Heres the code to export: I'm i goign about this wrong, is there a better way to achieve what i want in terms of performance. I need to get the user a csv file of data from a stored procedure.

public void ExcelExportCSV(SqlDataReader dr )
    {
        HttpResponse response = HttpContext.Current.Response;
        HttpContext context = HttpContext.Current;
        context.Response.Clear();

        while (dr.Read())
        {
            context.Response.Write(dr.GetValue(0)+ ",");
            context.Response.Write(dr.GetValue(1) + ",");
            context.Response.Write(dr.GetValue(2) + ",");
            context.Response.Write(dr.GetValue(3) + ",");
            context.Response.Write(dr.GetValue(4) + ",");
            context.Response.Write(dr.GetValue(5) + ",");
        }
        context.Response.Write(Environment.NewLine);
        context.Response.ContentType = "text/csv";
        context.Response.AppendHeader("Content-Disposition", "attachment; filename=membSel.csv");
        context.Response.End();
    }

C#.NET Programming

Avatar of undefined
Last Comment
national_fulfillment
ASKER CERTIFIED SOLUTION
Avatar of smulange
smulange
Flag of India image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of jagrut_patel
jagrut_patel
Flag of India image

Check whether setting executionTimeout attribute of httpRuntime element in web.config is useful. See this for more details about httpRuntime element.
Avatar of national_fulfillment

ASKER

i had a couple other issues but i think adding the timeout on the sql command did the trick. Thanks a bunch.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo