0

I want to create my own sql tool and I have a little problem with terminating running queries. This tool will be executing every kind of sql query: select, insert, update etc...

I'm using Devart with c#, winforms application. Here is my code:

        try
        {
            dt = null;
            dt = new OracleDataTable();
            dt.Connection = dp.sqlConnection;
            dt.SelectCommand = dp.sqlConnection.CreateCommand();
            dt.SelectCommand.CommandText = tbQuery.Text;
            IAsyncResult aRes = dt.BeginFill(null, null);

            SetStatus("In progress...");
            while (!aRes.IsCompleted)                        
            {
            }
            if (!cancel)
            {
                dt.EndFill(aRes);
                SetDgv(dt);
            }        
        }
        catch(Exception ex)
        {                    
            MessageBox.Show(ex.Message);
        }

This code is executing in another thread. So when I press Cancel button I do:

cancel = true; 
dt.CancelFetch();

It works, but not for every query. It works for query like that: select * from temp_table, where temp_table has 1mln records.. But.. I doesn't work with statement: select column from - this query has very complex "where" part and it returns only 50 records, but from table that has over 1mln records. I can't stop that..

Could You tell me how to stop every sql statement ? Is it good way to kill that thread where BeginFill method has been called?

Marshall
  • 1,195
  • 6
  • 30
  • 47
  • I would put the code in a thread and kill the thread, that's more userfriendly because your UI is still responsible and you can kill a thread more easily than a query, I believe. – jAC Dec 03 '12 at 12:16
  • 1
    Related: http://stackoverflow.com/q/9545560/458741, i.e. `alter system kill` might help. – Ben Dec 03 '12 at 12:54
  • I do that.. I have responsible UI. But I don't want to kill, I want to stop executing (executing or reading)... – Marshall Dec 03 '12 at 12:54

0 Answers0