3
I have a very time consuming SQL (more than 10 minutes) to return the data.
However, he is executed in a Thread and therefore the Mainthread continues to run normally. While SQL is running, the user can shut down the system, and there is the problem.
Because the system even closes, but the process keeps running in the task manager until SQL returns the requested data.
You can abort SQL execution immediately?
Dice:
- Delphi XE 7
- Firedac
- Firebird
- No use changing SQL to get faster, it is slow and not has to get away from it.
Mythread.Terminate; in theory would end, but I doubt it will end because the process is 'stuck' in the bank.
– Reginaldo Rigo
Exactly, the problem is not in closing Thread, but in the fact that it is stuck in the bank.
– Andrey
I don’t see how. Except by changing the logic. Sort by selecting gradually. So you don’t let the program close when you’re in the bank, knowing that it will come back soon and then decide whether to continue or not.
– Reginaldo Rigo
Note that just like your application, SQL Server also has control of processes and threads. I strongly believe there is
stored procedure
that you can use in the bank to kill a process there. The business is to discover the process id of the query in the bank...– Oralista de Sistemas
Exactly. I thought about Kill( id ), but...
– Reginaldo Rigo
I forgot to mention the database: Firebird
– Andrey
It got worse. There is no Kill in Firebird. It does not treat this issue per user killed one, kills all.
– Reginaldo Rigo
Create a method (e.g.:
FinalizarProcesso
) in your thread class with SQL. In it, callTerminateProcess(GetCurrentProcess, 0);
. Then, from the main thread you call this thread method with SQL, then call theTerminateProcess(GetCurrentProcess, 0);
in the main thread itself. By the way, I think that in the main thread there is no need, just finish normally with theApplication.Terminate
.– Alisson