• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

Store Procedure in Thread (ASP.NET)

HI

I have a store procedure that can take like 10 - 15 minutes.
I want to execute the SP in a Thread, because the user can cancel the query.

I try with Dim MyThread As New Thread(AddressOf runQuery)

So i put a start button (MyThread.Start()) an a cancel but (MyThread.Abort(),, i guest...)

My query runs fine, but i can't cancel de thread..

I'm using ASP.NET, with a SQL Server 2000 DB. And a WebService have the logic of the app...

WebForm -> WService -> VB Class -> DB

Any help please?
0
Alucard_cr
Asked:
Alucard_cr
  • 2
  • 2
1 Solution
 
vippxCommented:
Hi

Cancelling a thread that executes a stored procedure is a difficult task as the SP is run in a different process that is controlled by the DB server. So although the "thread" that started the execution of the thread the procedure would still execute.

However to know the inner workings of a thread.abort(), what happens is on calling abort it just raises a thread abort exception that is raised again after your catch block has executed. but again the finally block is excuted and then the thread is stopped.

so this is what you could do:

put a try catch block in the method that the thread would execute.

add a thread.join() immediately after the thread.abort() call. this would block your current thread until the aborted thread has stopped.

however just to let u know.. that wont abort the SP executing

0
 
Alucard_crAuthor Commented:
Thanks vippx, I'll do that and try a little more.

I'll wait for more comments...

Thank you
0
 
djwillmsCommented:
Closing the database connection should inform the database server to cancel executing the stored procedure.
0
 
Alucard_crAuthor Commented:
I'll try to cancel the query. Maybe a Command.Cancel() or with the DataAdapter...??
0
 
vippxCommented:
Yes ... the command.cancel() should cancel the command. but make sure that appropriate rollbacks are in place. too often, killed SPs are real messy
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now