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

asp.netexportresponse.writetext-files

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.

Best Answer

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).