Response.Write DataTable Data to Text File, ASP.net Hangs

10,863

Attach a remote debugger and find where its hanging?

You need to figure out if its the string writer loop, or the actual query code (which is not provided here).

Share:
10,863
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    Very odd problem as this is working perfectly on our old Classic ASP site. We are basically querying the database and exporting around 2200 lines of text to a Text File through Response.Write to be output to a dialog box and allows the user to save the file.

    Response.Clear() Response.ClearContent() Response.ClearHeaders()

        Dim fileName As String = "TECH" & test & ".txt"
    
        Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", fileName))
        Response.ContentType = "text/plain"
    
        Response.Write(strHeader)
    
        Dim sw As New IO.StringWriter()
    
        Dim dtRow As DataRow
        For Each dtRow In dt3.Rows
            sw.Write(dtRow.Item("RECORD") & vbCrLf)
        Next
    
        Response.Write(sw.ToString)
        Response.Write(strTrailer & intRecCount)
        Response.End()
    

    I can either use StringWriter or simply use Response.Write(dt.Rows(i).Item("RECORD").toString

    Either way, the Export is causing a horrendous hang on our development site. My local machine causes no hang and is almost instantaneous. The recordset isn't very large, and the lines it is writing are small.

    Anyone have any idea why this would be hanging? It does EVENTUALLY allow for a save and display the file, but it's well over 3-4 minutes.

  • Peter Ramos
    Peter Ramos over 15 years
    Shouldn't Response.Write automatically flush the buffer?
  • Joel Coehoorn
    Joel Coehoorn over 15 years
    You'd think that, but I've seen it happen. Also: reading his code he's pushing everything into response in one big operation.