473,695 Members | 2,777 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hard killing a thread that's got resources open (SqlDataAdapter , SqlConnection)

New to multi-threading (less than 24 hours at it <grin>)

Anyway, it's all making sense, and working fairly well
thus far, but I'm having a minor issue I'm not sure how
to get around.

I've got a form that uses SqlDataAdapter. It fires off
a thread to fill a DataSet. Not a big deal, this works.
I've also got a requirement that the Thread that's going
off to do the work -- if it takes too long, it has to
honor a timeout, or a cancellation request from the
user.

No problems here, I've got them both done and working
to where they kill the Thread (Thread.Abort() ). The
problem is, that killing the Thread leaves the SqlDataAdapter
in an inconsistent state, in particular, the SqlConnection
for the Procedures (InsertProcedur e, UpdateProcedure , etc) --
the SqlConnection is still open, but hosed and can't be
re-used.

If I try to .Close() it, I get an error. It can't be closed.

What I've done is to, just prior to the Thread.Abort(), I
issue a Cancel() on the Command object. This seems to have
fixed most of the issue, but not all. The Cancel() appears
to only *attempt* a true cancel of the command, and is not
actually successful every time. Of course, the other issue
is that .Cancle returns void, so I don't have a return
value to check if it actually was successful.

So, I do

theCommand.Canc el()
Thread.Abort()

and hope that the Command gets cancelled. Sometimes it's
not. This leaves me holding the bag, as the next time
the Adapter attempts to do something on that connection,
it's hosed. There's a lot of data access going on with
this form, so I keep reusing the same connection. That
gets to be a problem when you try to reuse a hosed
connection.

Are you following me on this?

What's a guy to do?

Nov 17 '05 #1
2 2491

I don't think aborting a thread like this is a good idea (I've been through
the wringer with almost exactly the same issue). I think aborting any .NET
thread that is making use of COM resources is generally considered bad
practice with unpredictable results. Cancel the command by all means, but
let the thread run through to terminate normally.

"Sgt. Sausage" <no****@nowhere .com> wrote in message
news:3b******** *************** ***@FUSE.NET...
New to multi-threading (less than 24 hours at it <grin>)

Anyway, it's all making sense, and working fairly well
thus far, but I'm having a minor issue I'm not sure how
to get around.

I've got a form that uses SqlDataAdapter. It fires off
a thread to fill a DataSet. Not a big deal, this works.
I've also got a requirement that the Thread that's going
off to do the work -- if it takes too long, it has to
honor a timeout, or a cancellation request from the
user.

No problems here, I've got them both done and working
to where they kill the Thread (Thread.Abort() ). The
problem is, that killing the Thread leaves the SqlDataAdapter
in an inconsistent state, in particular, the SqlConnection
for the Procedures (InsertProcedur e, UpdateProcedure , etc) --
the SqlConnection is still open, but hosed and can't be
re-used.

If I try to .Close() it, I get an error. It can't be closed.

What I've done is to, just prior to the Thread.Abort(), I
issue a Cancel() on the Command object. This seems to have
fixed most of the issue, but not all. The Cancel() appears
to only *attempt* a true cancel of the command, and is not
actually successful every time. Of course, the other issue
is that .Cancle returns void, so I don't have a return
value to check if it actually was successful.

So, I do

theCommand.Canc el()
Thread.Abort()

and hope that the Command gets cancelled. Sometimes it's
not. This leaves me holding the bag, as the next time
the Adapter attempts to do something on that connection,
it's hosed. There's a lot of data access going on with
this form, so I keep reusing the same connection. That
gets to be a problem when you try to reuse a hosed
connection.

Are you following me on this?

What's a guy to do?

Nov 17 '05 #2

"Robin Tucker" <id************ *************@r eallyidont.com> wrote in
message news:d6******** ***********@new s.demon.co.uk.. .

I don't think aborting a thread like this is a good idea (I've been
through the wringer with almost exactly the same issue). I think aborting
any .NET thread that is making use of COM resources is generally
considered bad practice with unpredictable results. Cancel the command by
all means, but let the thread run through to terminate normally.


Yeah, I suppose that's the route to go.

I'll have to change a few things to do this, but it's TheRightThingTo Do(tm).
Nov 17 '05 #3

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

Similar topics

8
12402
by: Rob | last post by:
Hello, I've got an issue where a process in a third party application has a dll which while exiting sort of freezes and runs away with processor cycles. i've written a block of code so that I can drill down into the process, and get the offending Thread's ID (since the only ones that will have the issue have higher User processor Time). But, I can't figure out how to have my .Net app 'kill' or 'suspend' a Thread
6
2206
by: Mike | last post by:
We are intermitantly receiving this error on our website. ExecuteReader requires an open and available Connection. The connection's current state is connecting. Following is the code from the Load event of the aspx page. The last line is where the error occurs. Does anyone have any ideas what is causing this? Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim MyDA As New...
2
3175
by: rn5a | last post by:
The following code resides in a VB class file name GetOrder.vb (this class file exists in the App_Code directory): Namespace Shop Public Class Orders Public Function ViewOrder(ByVal UserID As Integer, ByVal OrderID As Integer) As SqlDataAdapter Dim sqlDapter As SqlDataAdapter Dim sqlConn As SqlConnection
0
1838
by: Fendi Baba | last post by:
I created an ASP.net page which opens excel. This works fine in Office 2007. However, Excel 2003 runs in an error which states "cannot read output file". Hee is the VB code and below is the ASPX code. Imports System.Data.SqlClient Imports System.Web.Configuration Imports System.Web.UI
0
8631
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9115
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8825
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7661
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5839
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4340
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4579
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3003
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 we have to send another system
3
1976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.