Can I manually stop a oracle Sql executing immediately only using c# code without quiting a process? RRS feed

  • Question

  • Hi,

    The scenario is:

    I started a thread to load data from oracle, but the sql executing is very slow(about 5min or more). When user switch to other pages, the thread was still running, I tried a lot of ways to interrupt it:

    to Abort the thread.
    to Interrupt the thread
    to Close and Dispose the connection
    to Cancel the command

    but they just didn't work, the SQL was still executing(I found out the SQL was still in Oracle sessions).

    Of course, when I quit the program process, the Sql was stopped.

    Finally I figured out a way to kill the oracle sql by PL/SQL 'alter system kill session'.

    Is there any better way to do this?

    Or is there any way to do this only in C# code without any extra Sql executing?

    Why when I quited the program process, the orcale sql executing was stopped immediately?(memory cleaned?)

    Thank you very much


    Saturday, November 6, 2010 7:06 AM


  • > to Abort the thread.
    > to Interrupt the thread

    These are not nice as it is hard or impossible to coordinate that they are performed at a "good" time.  These can corrupt your process's state and lead to hard-to-diagnose problems.

    System.Data.OracleClient.OracleCommand has a Cancel method (because of its base class), but it is a no op.  Perhaps other drivers provide an implementation.  The driver included with the .NET is generally not recommended.  I'm not familiar with Oracle.

    To conclude, there is no safe way to cancel using the driver included with .NET.  Ask around on Oracle's support systems.

    From here,, sounds like you need ODP.NET or higher.





    • Marked as answer by SamAgain Friday, November 12, 2010 8:39 AM
    Saturday, November 6, 2010 3:44 PM