Aborting a stored procedure?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • codefragment@googlemail.com

    Aborting a stored procedure?

    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
  • Erland Sommarskog

    #2
    Re: Aborting a stored procedure?

    (codefragment@g ooglemail.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.Canc el method.


    --
    Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.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

    Comment

    • codefragment@googlemail.com

      #3
      Re: Aborting a stored procedure?

      which brought me to this article, thanks for the help, didn't know
      that.


      Comment

      • joeNOSPAM@BEA.com

        #4
        Re: Aborting a stored procedure?

        On Nov 5, 2:03 am, "codefragm...@g ooglemail.com"
        <codefragm...@g ooglemail.comwr ote:
        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

        Comment

        • codefragment@googlemail.com

          #5
          Re: Aborting a stored procedure?

          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.

          Comment

          • Dan Guzman

            #6
            Re: Aborting a stored procedure?

            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


            <codefragment@g ooglemail.comwr ote in message
            news:85b06de3-db19-457e-b3e7-b8665f042776@v1 6g2000prc.googl egroups.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.
            >

            Comment

            Working...