One solution that came up in my mind is to have a static List
of currently Running SqlCommands
, whenever user invokes cancel you can extract the Command from this static list, and then cancel it. The page that is executing the command will receive the command cancel exception, it then can handle it appropriately.
Here are the things that you need to handle:
- Somehow user interface should have some key, so that when you press the cancel button, user interface will then send that key to the cancel routine, and cancel routine will extract the
SqlCommand
using that key and call its Cancel
method.
- Cancellation calls should be done through AJAX
- Proper locking should be done for thread-safety
Update:
I am adding some details here,
- Here is the link of Project http://goo.gl/noKUmj
- Above project is a Web Form Application
- You may add as many controllers as you want in this project, the routing code has already been added in
Global.ascx
, so new controllers should work
- But for new IFRAME cancellation you don't have to add another controller. You just need to pass the
PageName
(as key) to the Cancel Controller
- LIMITATION: This project has limitation that if you hit cancel button for an IFRAME, it is going to cancel all the current requests, which means in a multi-user environment, if one user cancels the IFRAME-1, all IFRAME-1 are going to be cancelled for every other user.
- You can cancel multiple IFRAMEs easily, as you can see the cancel button code it is executing a JavaScript code, you just need to call multiple Cancellation Codes in 1 click.
As you may have already seen the project, it is using PageName
as Key to extract the SqlCommand
from List
. Due to this we have the limitation as I have mentioned above. Since PageName
will be same for multiple SqlCommand
s.
To overcome this limitation, you can generate a GUID
as Key and pass this GUID
in QueryString
to Form1.aspx
and Form2.aspx
pages, so that they add the command in List
using these GUID
s. These keys should be generated at the time of host page rendering or in JavaScript.
If you don't want to do the RnD, here is the updated project which uses GUID
as Key. :) http://goo.gl/I86S7Z