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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Programmaticaly cancel a SQL command sent to MS SQL Server?

Status
Not open for further replies.

huckfinn19

Programmer
May 16, 2003
90
CA
Hi!

I am using .Net's C# language in an application that is using a SQL Server database. Some of the calls in my application to the DB take quite a while to handout the results and I would like to give my users the possibility to cancel the request if they think it's taking too long. When using the SQL Enterprise application, there is a cancel button that can be hit to stop the request in the middle of it's processing, so I guess it's also possible programmatically.

Therefore, I would like to know if someone could guide me on how to programmatically and asynchronously cancel a SQL command that was sent to SQL Server?

Thanks!

Huck
 
Use threads. Open a new thread and give it the sql job. When the user press on something, call Thread.Abort()
 
Hi Korach, thanks for your answer. Your solution will work fine, the only concern I have with it is that the job might keep running on the distant SQL Server? I might be wrong, I wonder what happens when a connection is closed with the server like it will happen when I call the abort on the thread.
 
I think who developed SQL Server thought about that, but ask this question in the SQL Server forum.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top