SQL Server Developer Center > SQL Server Forums > .NET Framework inside SQL Server > Handle "Query was cancelled by user." in CLR StoredProc
Ask a questionAsk a question
 

AnswerHandle "Query was cancelled by user." in CLR StoredProc

  • Tuesday, October 13, 2009 12:25 PMReg_H Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi everyone

    How can one elegantly handle the situation where the user cancels the CLR procedure (Alt+Break or job cancellation etc)?

    There doesn't appear to be any event or way to handle it. I've spent the past few hours trying to find a way to determine if the procedure had been cancelled by the user.  What seems to be happening is that the CLR runtime for the procedure seems to get cleaned up immediately from when it is cancelled - it's like the runtime for the procedure has already been disposed. If I set a breakpoint and cancel the SP then I find my code context is immediately invalid.

    I was hoping to use a global Mutex but I whilst I can create a global mutex if the proc gets cancelled then the mutex still remains because it hasn't been released, due to the abrupt termination of the CLR procedure.

    This may be by-design, but is there any way this can be handled?

    Thanks

Answers

  • Thursday, October 15, 2009 2:08 AMDan GuzmanMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I don't think there is a difference between a CLR and T-SQL stored procedure in this regard.  Cancel mean cancel; no user code executes after the attention signal.
    Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
    • Marked As Answer byReg_H Monday, October 19, 2009 2:47 PM
    •  

All Replies

  • Thursday, October 15, 2009 2:08 AMDan GuzmanMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    I don't think there is a difference between a CLR and T-SQL stored procedure in this regard.  Cancel mean cancel; no user code executes after the attention signal.
    Dan Guzman, SQL Server MVP, http://weblogs.sqlteam.com/dang/
    • Marked As Answer byReg_H Monday, October 19, 2009 2:47 PM
    •