Dmitry Onoshko 0 Posted October 23 I have a large set of data to insert into a MySQL/MariaDB table. For now I decided to use FireDAC’s array DML feature, so I create a TFDStoredProc, feed it with all the data and call Execute method (all the stuff in a TTask to avoid hanging the UI). Now when the user wants to close the application, the task should obviously be interrupted to prevent the application from hanging in the processes list for quite a long time. So, from the UI thread (say, TForm.OnCloseQuery, doesn’t really matter) I call TFDConnection.AbortJob on the connection I’ve assigned to the TFDStoredProc before executing it. The problem is that AbortJob raises an exception: Quote Project MyProgram.exe raised exception class EMySQLNativeException with message '[FireDAC][Phys][MySQL] You are not owner of thread 70'. So, the array DML query doesn’t get aborted, the program stays hanging until the TDStoredProc.Execute returns. Has anyone ever had such problem? Any help is appreciated. Share this post Link to post
Die Holländer 45 Posted October 23 To avoid hanging of the UI I use FireDac CmdExecMode: MyQuery.BeforeOpen:=FDQuery1BeforeOpen; MyQuery.AfterOpen:=FDQuery1AfterOpen; MyQuery.ResourceOptions.CmdExecMode:=amAsync Execute MyQuery; procedure FDQuery1BeforeOpen(DataSet: TDataSet); Begin fCurTime:=now; JvDesktopAlert2.HeaderText:='HeaderText'; JvDesktopAlert2.MessageText:='Fetching Data..'; JvDesktopAlert2.Execute(self.Handle); MyQuery.BeforeOpen := nil; End; procedure FDQuery1AfterOpen(DataSet: TDataSet); Begin //Reset MyQuery.ResourceOptions.CmdExecMode:=amBlocking; MyQuery.AfterOpen:=nil; Sleep(3000); JvDesktopAlert2.MessageText:='Execute Time: '+IntToStr(SecondsBetween(Now,fCurTime))+' Sec.'; JvDesktopAlert2.Close(False); //Extra Things.. End; Share this post Link to post
Dmitry Onoshko 0 Posted October 24 17 hours ago, Die Holländer said: To avoid hanging of the UI I use FireDac CmdExecMode: MyQuery.BeforeOpen:=FDQuery1BeforeOpen; MyQuery.AfterOpen:=FDQuery1AfterOpen; MyQuery.ResourceOptions.CmdExecMode:=amAsync Execute MyQuery; Well, my problem is not asynchronous query execution but the problem of aborting it. AbortJob seems to work for ordinary queries (or maybe I just can’t catch the particular moment it would fail) while for array DML it fails quite often. Share this post Link to post