Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cancelling a Query

Status
Not open for further replies.

miket26

Programmer
Apr 13, 2004
63
0
0
CA
Hello,

I'm having the most difficulty trying to figure out a way to cancel a long-running query using ado.net and the odbc provider. No matter what I try to do, it will sit there and wait for the database to respond with the records before it will do any action I requested, such as calling the odbcCommand.cancel method. I don't understand why they have this method if it doesn't work when its waiting to hear back from the database. I greatly appreciate if anyone can shed some light on this problem.

Thanks
 
Your best bet is going to be threading. It's not too scarey and there was a great thread on it last week. Thread796-1083662

Towards the end of the thread we get into a discussion about exiting a thread early. If you need source code examples, I can probrably dig something up.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
It seems the way you recommend to do it is call the Abort method, and deal with the thrown exception or have a 'Finally' to clean up everything. I'm wondering though, what about if the program is shut down by the user before the 'Finally' clause is reached. I ask this because it seems that even though I Abort the thread, the objects that were created in the thread are still being tied up by the database, and the exception isn't thrown until they are released. Should I worry about this?

Thanks
 
You can trap your main form's closing event so that you know when the user is trying to exit the program and then ensure that all threads are properly cleaned up.

Hope this helps.
 
I made that modification. On the Closed event, I go through an arraylist of all my threads created, and abort them if they're running. I think this should do the trick and tie up any loose ends. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top