Page 1 of 1

Can you cancel a running OleDB query?

Posted: 16.11.2020, 22:42
by MJFShark
Hi all!

I've been testing the TZConnection.AbortOperation method which works great for the supported drivers. I'm also using SQL Server through the OleDB interface, and it doesn't support this method, however I notice it has a "Cancel" method on the statement objects. Is that in any way similar? I tried using it but no luck (I think it doesn't do what I thought it might.) Any info appreciated!

-Mark

Re: Can you cancel a running OleDB query?

Posted: 17.11.2020, 13:14
by aehimself
Hi Mark,

I'm glad to hear it works fine for you :) I do believe I saw those too when I implemented the basics of the .AbortOperation logic. See ZDbcConnection.pas:1071:

Code: Select all

function TZAbstractDbcConnection.AbortOperation: Integer;
begin
//  Would this work...?
//  for i := fRegisteredStatements.Count-1 downto 0 do
//   IZStatement(fRegisteredStatements[i]).Cancel;
  Raise EZUnsupportedException.Create(SUnsupportedOperation);
end;
I implemented the "normal" way (telling the server to abort) where I could, but I had no chance to test on others as I have only a MySQL and an MSSQL server at home.

You can try to uncomment those lines and see if it works, I suppose?
But, even if we skip the execution of a statement on client side, either the query will still be running or simply resources will still be locked on the server side until it finishes... so be careful.