Groups | Blog | Home
all groups > vb.net data > february 2006 >

vb.net data : Cancelling a SQL statement in a Thread


SQLScott
2/3/2006 6:06:42 AM
I have an application in which threads are used in some cases to query and
return data from a SQL Server 2005 database. I know how to cancel threads,
that is not the problem. However, the problem is I would like to be able to
cancel the execution of the SQL statement in the thread. What happens is
that even though I cancel the thread, the thread really doesn't cancel until
the SQL Statement is finished executing.

Does this make sens? I hope I explained it well enough. When I am in SQL
Server Query Analyzer or Management Studio and execute a T-SQL statement, I
can cancel the executing query by clicking a simple button on the toolbar. I
am looking for this same functionality via my application. I execute a query
in my app via a thread, I want to be able to cancel the thread AND the query.

Is this possible? Many thanks in advance...

Scott
--
Thanks,

Paul Clement
2/3/2006 12:03:46 PM
[quoted text, click to view]

¤ I have an application in which threads are used in some cases to query and
¤ return data from a SQL Server 2005 database. I know how to cancel threads,
¤ that is not the problem. However, the problem is I would like to be able to
¤ cancel the execution of the SQL statement in the thread. What happens is
¤ that even though I cancel the thread, the thread really doesn't cancel until
¤ the SQL Statement is finished executing.
¤
¤ Does this make sens? I hope I explained it well enough. When I am in SQL
¤ Server Query Analyzer or Management Studio and execute a T-SQL statement, I
¤ can cancel the executing query by clicking a simple button on the toolbar. I
¤ am looking for this same functionality via my application. I execute a query
¤ in my app via a thread, I want to be able to cancel the thread AND the query.
¤
¤ Is this possible? Many thanks in advance...

In order to do this you would probably need to run your queries asynchronously. The following
article may help:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/async2.asp


Paul
~~~~
AddThis Social Bookmark Button