timeout when writing results of query to text file RRS feed

  • Question

  • User-1005337932 posted

    Hi all.

    I am looking for a solution to elegantly write the results of a query to a text file. The query returns about 5000 rows and before writing there's a lot of processing and formatting to be done in code before the file is actually written to a folder on the site. The whole process takes about 4 to 5 minutes. Most of the time, the end user has a never ending hourglass and the page with a download link never gets displayed. But the file is actually written to disk.

    What are the options? I have been thinking about using jQuery ajax, but it's not quite clear how to actually do it. Are there better ways?

    Snippets and/or demos welcome, I'm just starting to become comfortable with C# and ASP.net.


    Friday, December 23, 2016 11:43 AM

All replies

  • User753101303 posted


    I would try https://www.asp.net/signalr which is more general but can be used to report actual progress from the server to the client side. Something that last 5 minutes start maybe to be a good candidate for a "fire and forget" approach ie you the task is queued and processed maybe by another system and the user is warned when done (either with a notification when browsing the site or by mail with a download link).

    Of course you could also start by double checking that the processing really needs to take that much time (for example if you concat strings often a know approach is to use a StringBuilder).

    Try perhaps to see how much time it takes with a minimal amount of processing. This is just to see what is the minimum amount of time you can expect. The bigger the difference is, the more likely you should be able to reorganize all this work to speed it up.

    Friday, December 23, 2016 11:53 AM
  • User-1005337932 posted

    Thank you for quick reply. I am going to look at SignalR and Stringbuilder right away.

    Friday, December 23, 2016 12:15 PM
  • User1853794821 posted

    Is your query a SQL query

    Show table structure, query code, and c# code

    Some SQL when not understood can result in very long runtmes

    Friday, December 23, 2016 1:57 PM
  • User-1005337932 posted


    Is your query a SQL query

    Show table structure, query code, and c# code

    Some SQL when not understood can result in very long runtmes

    The query is executed in Under less than a second. It's the code, but I have no other choice: a lot of calculations to do (a money etc. thing).

    Friday, December 23, 2016 2:51 PM
  • User-1005337932 posted

    I have been looking at SignalR and it seems it would be a good choice. However, I have just switched form 16 years of Classic ASP to Asp.net Web Pages with Razor last year and the sample applications (MVC) I have found on Codeproject all seem very complicated because I am lacking basic knowledge of MVC. I don't know where to start, which is very discouraging.

    Anyway, I keep on searching...

    Saturday, December 24, 2016 12:33 PM
  • User-2057865890 posted

    Hi Pvermeulen,


    StringBuilder sb = new StringBuilder();
    string output = "Output";
    string text = sb.ToString();
    Response.ContentType = "text/plain";
    Response.AddHeader("content-disposition", "attachment;filename=SqlExport.txt");




    Best Regards,


    Monday, December 26, 2016 8:19 AM