How can I cancel a long-running query from my code in a differentthread

  • Thread starter Thread starter Big Daddy
  • Start date Start date
B

Big Daddy

If I have a thread that running a long query, is it possible for a
different thread to cancel the query? I am using SQL Server and C#.
I have tried aborting the thread that is doing the query, and that
doesn't work. I have tried using a different thread to run a KILL
command on the SQL Server, and that is successful. But in order to
run a KILL command, I have to know the SPID of the query that should
be killed. I don't know how to get this. I am using the Entity
Framework for the long-running query. I am wondering if there's a way
to find the SPID of the query being run through EF. I could try to
run a query that says "select @@SPID" before running the long-running
query, but I don' know how to do this with my EF objects. Any ideas?

thanks in advance,
John
 
Back
Top