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?