Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It would appear that you are not the first to ask: <a href="https://forums.oracle.com/forums/thread.jspa?threadID=2125208" rel="nofollow">https://forums.oracle.com/forums/thread.jspa?threadID=2125208</a></p> <p>You could monitor within the loop over reader.Read() the elapsed time and exit the loop. That's nice and simple but of course it's only going to be able to exit after a potentially long running call to Read finishes.</p> <p>Your best bet would probably be to do the loop within a Task on a separate thread, monitor it, and then call cmd.Cancel on the original thread:</p> <pre><code>[Test] public void TimeBasicSql() { using (OracleConnection con = new OracleConnection("User ID=id; Password=pass; Data Source=db;")) using (OracleCommand cmd = new OracleCommand()) { con.Open(); cmd.Connection = con; Console.WriteLine("Executing Query..."); try { cmd.CommandTimeout = 1; String sql = "begin open :o_cur1 for select count(*) from all_objects, all_objects; end;"; cmd.CommandText = sql; cmd.Parameters.Add(new OracleParameter("o_cur1", OracleDbType.RefCursor) { Direction = ParameterDirection.Output }); var task = System.Threading.Tasks.Task.Factory.StartNew(() =&gt; { try { Stopwatch watch1 = Stopwatch.StartNew(); OracleDataReader reader = cmd.ExecuteReader(); watch1.Stop(); Console.WriteLine("Query complete. Execution time: {0} ms", watch1.ElapsedMilliseconds); int counter = 0; Stopwatch watch2 = Stopwatch.StartNew(); if (reader.Read()) counter++; watch2.Stop(); Console.WriteLine("First record read: {0} ms", watch2.ElapsedMilliseconds); Stopwatch watch3 = Stopwatch.StartNew(); while (reader.Read()) { counter++; } watch3.Stop(); Console.WriteLine("Records 2..n read: {0} ms", watch3.ElapsedMilliseconds); Console.WriteLine("Records read: {0}", counter); } catch (OracleException ex) { Console.WriteLine("Exception was thrown: {0}", ex); } }); if (!task.Wait(cmd.CommandTimeout * 1000)) { Console.WriteLine("Timeout exceeded. Cancelling..."); cmd.Cancel(); } } catch (OracleException ex) { Console.WriteLine("Exception was thrown: {0}", ex); } } </code></pre> <p>It's worth noting that the ORA-01013 exception is thrown on the worker thread and not on the thread calling OracleCommand.Cancel.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload