473,508 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

thread was being aborted

I have some code that creates and writes to an excel file. Right as I
response.end() to avoid HTML in the Excel document, I get an exception:

---------------

An attempt to log the following error
failed:System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()

-----------------

Here's my code
Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter(Session("savedShasSql"),
connection1.conString)
da.Fill(ds, "ShasExcel")
Dim dt As DataTable = ds.Tables("ShasExcel")

'This code was dumping html into the spreadsheet
'Response.ContentType = "application/ms-excel"
'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
'Response.Write(ConvertDtToTDF(dt))

'This is the new code
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
Response.Clear()
Response.Write(ConvertDtToTDF(dt))
Response.End()

Catch ex As Exception
ExceptionManager.Publish(ex)
End Try

End Sub

Private Function ConvertDtToTDF(ByVal dt As DataTable) As String

Try

Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer

'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next

Response.Write(vbCrLf)

'Output Data

For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next

Catch ex As Exception
ExceptionManager.Publish(ex)

End Try

End Function

_____
DC G
Nov 19 '05 #1
4 3021
Gringo,

you might want to replace Response.End() with Response.Flush.

Let me know if this works for you.

Daniel Walzenbach
"DC Gringo" <dc******@visiontechnology.net> schrieb im Newsbeitrag
news:OP**************@tk2msftngp13.phx.gbl...
I have some code that creates and writes to an excel file. Right as I
response.end() to avoid HTML in the Excel document, I get an exception:

---------------

An attempt to log the following error
failed:System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()

-----------------

Here's my code
Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter(Session("savedShasSql"),
connection1.conString)
da.Fill(ds, "ShasExcel")
Dim dt As DataTable = ds.Tables("ShasExcel")

'This code was dumping html into the spreadsheet
'Response.ContentType = "application/ms-excel"
'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
'Response.Write(ConvertDtToTDF(dt))

'This is the new code
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
Response.Clear()
Response.Write(ConvertDtToTDF(dt))
Response.End()

Catch ex As Exception
ExceptionManager.Publish(ex)
End Try

End Sub

Private Function ConvertDtToTDF(ByVal dt As DataTable) As String

Try

Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer

'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next

Response.Write(vbCrLf)

'Output Data

For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next

Catch ex As Exception
ExceptionManager.Publish(ex)

End Try

End Function

_____
DC G

Nov 19 '05 #2
Daniel,

Sorry, it didn't work. I didn't get the error, but the HTML returned to the
Excel file. Putting the response.flush() after the response.close() or vice
versa still generated the error.

_____
DC G
"Daniel Walzenbach" <da***************@newsgroup.nospam> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Gringo,

you might want to replace Response.End() with Response.Flush.

Let me know if this works for you.

Daniel Walzenbach
"DC Gringo" <dc******@visiontechnology.net> schrieb im Newsbeitrag
news:OP**************@tk2msftngp13.phx.gbl...
I have some code that creates and writes to an excel file. Right as I
response.end() to avoid HTML in the Excel document, I get an exception:

---------------

An attempt to log the following error
failed:System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()

-----------------

Here's my code
Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter(Session("savedShasSql"),
connection1.conString)
da.Fill(ds, "ShasExcel")
Dim dt As DataTable = ds.Tables("ShasExcel")

'This code was dumping html into the spreadsheet
'Response.ContentType = "application/ms-excel"
'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
'Response.Write(ConvertDtToTDF(dt))

'This is the new code
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
Response.Clear()
Response.Write(ConvertDtToTDF(dt))
Response.End()

Catch ex As Exception
ExceptionManager.Publish(ex)
End Try

End Sub

Private Function ConvertDtToTDF(ByVal dt As DataTable) As String

Try

Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer

'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next

Response.Write(vbCrLf)

'Output Data

For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next

Catch ex As Exception
ExceptionManager.Publish(ex)

End Try

End Function

_____
DC G


Nov 19 '05 #3
Yes, this is the way ASP.NET attempts to insure that the processing halts
for the current request -- they throw a ThreadAbortException. Sort of odd,
eh? Well, the magic with a ThreadAbortException is that if you put a try/catch
around it, it still gets thrown outside your catch -- they're doing this
so you don't catch their attempt to terminate the request. So, in short,
it's just how it works.

-Brock
DevelopMentor
http://staff.develop.com/ballen
I have some code that creates and writes to an excel file. Right as I
response.end() to avoid HTML in the Excel document, I get an
exception:

---------------

An attempt to log the following error
failed:System.Threading.ThreadAbortException: Thread was being
aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()
-----------------

Here's my code

Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e
As System.EventArgs)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter(Session("savedShasSql"),
connection1.conString)
da.Fill(ds, "ShasExcel")
Dim dt As DataTable = ds.Tables("ShasExcel")
'This code was dumping html into the spreadsheet
'Response.ContentType = "application/ms-excel"
'Response.AddHeader("Content-Disposition",
"inline;filename=shas.xls")
'Response.Write(ConvertDtToTDF(dt))
'This is the new code
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition",
"inline;filename=shas.xls")
Response.Clear()
Response.Write(ConvertDtToTDF(dt))
Response.End()
Catch ex As Exception
ExceptionManager.Publish(ex)
End Try
End Sub

Private Function ConvertDtToTDF(ByVal dt As DataTable) As String

Try

Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer
'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next
Response.Write(vbCrLf)

'Output Data

For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next
Catch ex As Exception
ExceptionManager.Publish(ex)
End Try

End Function

_____
DC G


Nov 19 '05 #4
a Response.End() does a flush, then kills the current thread (to stop
continued processing). ignore the thread abort in your catch

-- bruce (sqlwork.com)


"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:OP**************@tk2msftngp13.phx.gbl...
I have some code that creates and writes to an excel file. Right as I
response.end() to avoid HTML in the Excel document, I get an exception:

---------------

An attempt to log the following error
failed:System.Threading.ThreadAbortException: Thread was being aborted.
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
at System.Web.HttpResponse.End()

-----------------

Here's my code
Public Sub btnShasExcel_OnClick(ByVal sender As System.Object, ByVal e As
System.EventArgs)

Try
Dim ds As New DataSet
Dim da As New SqlDataAdapter(Session("savedShasSql"),
connection1.conString)
da.Fill(ds, "ShasExcel")
Dim dt As DataTable = ds.Tables("ShasExcel")

'This code was dumping html into the spreadsheet
'Response.ContentType = "application/ms-excel"
'Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
'Response.Write(ConvertDtToTDF(dt))

'This is the new code
Response.ContentType = "application/ms-excel"
Response.AddHeader("Content-Disposition", "inline;filename=shas.xls")
Response.Clear()
Response.Write(ConvertDtToTDF(dt))
Response.End()

Catch ex As Exception
ExceptionManager.Publish(ex)
End Try

End Sub

Private Function ConvertDtToTDF(ByVal dt As DataTable) As String

Try

Dim dr As DataRow, ary() As Object, i As Integer
Dim iCol As Integer

'Output Column Headers
For iCol = 0 To dt.Columns.Count - 1
Response.Write(dt.Columns(iCol).ToString & vbTab)
Next

Response.Write(vbCrLf)

'Output Data

For Each dr In dt.Rows
ary = dr.ItemArray
For i = 0 To UBound(ary)
Response.Write(ary(i).ToString & vbTab)
Next
Response.Write(vbCrLf)
Next

Catch ex As Exception
ExceptionManager.Publish(ex)

End Try

End Function

_____
DC G

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1417
by: Johanna | last post by:
Hello, Thread was being aborted exception is thrown by my asp.net application. I hope someone could help me with this error that I get in windows 2003 server. This error has not occured with...
3
2471
by: Johanna | last post by:
Hello, Thread was being aborted exception is thrown by IIS for my asp.net application on win2003 server. This error has not yet occured with the same asp.net application on windows 2000...
1
4246
by: Keith F. | last post by:
Hi, I have an asp.net web app that is intermittently throwing "Thread was being aborted." errors in my data access component. This seems to occur when the app is under a heavier than normal load....
3
3238
by: Keith F. | last post by:
Hi, I have an asp.net web app that is intermittently throwing "Thread was being aborted." errors in my data access component. This seems to occur when the app is under a heavier than normal load....
1
662
by: Josef K. | last post by:
I've started getting "Thread was being aborted" errors. This errormessage has me puzzled. I'm using the same very simple approach throughout the application, and it works elsewhere: -- my aspx...
5
495
by: Jimi | last post by:
Hi all, I have a user control which raises an event to the parent page when a person clicks on a link in a datagrid. In the event handler inside the parent page I construct a url to redirect to...
4
4889
by: Totto | last post by:
Hi, I'm doing a server.transfer from a click event of a button, but an exception is raised with "Thread was being aborted" Anyone know why? Thanks Tor
9
3258
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my...
2
22950
by: Daniel Knöpfel | last post by:
Hi I am develloping an asp.net 2.0 application. For some tasks (daily notifications to users via email), we use background threads. I rather have this task as background thread of the asp.net...
1
1175
by: malu | last post by:
Hi I faced one exception when use the thread in c#. I start the thread in a class.Then i start the thread thru the main method constructor.In that thred i use the thred.sleep() method. Then...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7377
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7036
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7489
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5624
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5047
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4705
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1547
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.