By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,806 Members | 1,829 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,806 IT Pros & Developers. It's quick & easy.

Aborting a stored procedure?

P: n/a
Hi
Is there any way of aborting a stored procedure? I'd want to do this
from c# using async connections but if its possible from query
analyser I'd like to know.
How does the stop button work in query analyser?

thanks
Nov 3 '08 #1
Share this Question
Share on Google+
5 Replies


P: n/a
(co**********@googlemail.com) writes:
Is there any way of aborting a stored procedure? I'd want to do this
from c# using async connections but if its possible from query
analyser I'd like to know.
How does the stop button work in query analyser?
It sends an attention signal to SQL Server.

I would guess that method to use in C# is the SqlCommand.Cancel method.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinf...ons/books.mspx

Nov 3 '08 #2

P: n/a
which brought me to this article, thanks for the help, didn't know
that.

http://blogs.msdn.com/khen1234/archi...20/483015.aspx
Nov 5 '08 #3

P: n/a
On Nov 5, 2:03*am, "codefragm...@googlemail.com"
<codefragm...@googlemail.comwrote:
which brought me to this article, thanks for the help, didn't know
that.

http://blogs.msdn.com/khen1234/archi...20/483015.aspx
Bear in mind that the speed with which the DBMS responds to the
cancel signal is indeterminate. The DBMS architecture is a non-
preemptive
threading model, so for the most part, the executing thread itself
decides
when it's going to check for any external messages, such as the rare
cancel.
If it's making good progress and not needing to wait for I/O, a user
thread
may often complete before ever discovering it got a cancel signal.
Back
in my C client days I ran an experiment where I sent a long list of
individual
update statements, each inserting into a table. I sent these all in a
single
SQL string to the DBMS, and *immediately after sending the string* I
sent
a cancel. I was then able to determine how many of the rows got
inserted
before the cancel got heeded. I remember getting 472 inserts completed
out of a 500-line batch.
Joe Weinstein at Oracle
Nov 5 '08 #4

P: n/a
I remember getting 472 inserts completed out of a 500-line batch.
Joe Weinstein at Oracle
I gather that its, if not flaky, unpredictable in what it does. Nice
to know though.

Nov 7 '08 #5

P: n/a
A word of caution regarding cancelling a proc: if the proc includes an
explicit transaction, the transaction will remain open after the cancel
(unless XACT_ABORT is ON). One method to address this is to execute the
following after the cancel:

IF @@TRANCOUNT 0 ROLLBACK

--
Hope this helps.

Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/

<co**********@googlemail.comwrote in message
news:85**********************************@v16g2000 prc.googlegroups.com...
>I remember getting 472 inserts completed out of a 500-line batch.
Joe Weinstein at Oracle

I gather that its, if not flaky, unpredictable in what it does. Nice
to know though.
Nov 7 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.