2

I am using the TADOConnection object in Delphi XE but this appears to be an ADO issue, not a Delphi issue:

Scenario: I am trying to close and free a TADOConnection object connected to Sybase. The connection is waiting for a response from a remote Sybase server after sending a long running query to Sybase - in the interim the user decided it's taking too long for a response and wants to abort the process.

Problem: When trying to close or free the ADOConnection object when it is waiting for the Sybase response, I receive this error message:

"Operation cannot be performed while executing asynchronously", and my calls to close/free fail. So, when aborting the process I always end up with a leak and an orphan connection - not the end of the world in my case, but not desirable either.

This message corresponds to ADO Error 3711-adErrStillExecuting - Operation cannot be performed while executing asynchronously.

See http://msdn.microsoft.com/en-us/library/windows/desktop/ms681549%28v=vs.85%29.aspx

Question: How can I change the state of the ADOConnection object so that it is no longer waiting for the Sybase response, which should allow me to call TADOConnection.close and TADOConnection.free.

I have access to the ADOConnection itself via the Delphi TADOConnection wrapper so I can use whatever is available in the ADO TLB to accomplish this.

Note - I have not explicitely instructed ADO to perform an asynchronous operation- I assume that this is the default in the context in which I am running (thread spawned within a TISAPI application response). Regardless, I assume that if the ADO call was blocking it would be more even more difficult to abort.

Vector
  • 10,879
  • 12
  • 61
  • 101
  • Is there a reason you can't have the abort wait (in a thread) for the completion and then close normally? – Warren P Feb 02 '12 at 15:59
  • The architecture is a bit complex here - I've only explained the relevant part - an explicit abort at the time is the most efficient way to get this done and requires the least code mods. I could implement mechanisms to negotiate the issue the way you suggested - I considerd that - but not worth the trouble - ISAPI app and Sybase have plenty of resources and are periodically recycled anyhow. Just looking for a quick and dirty answer to the question. – Vector Feb 02 '12 at 16:29

1 Answers1

3

look at this response.

In particular the DataSet.Recordset.Cancel; part. You need to cancel the query first before you close the connection.

Community
  • 1
  • 1
whosrdaddy
  • 11,720
  • 4
  • 50
  • 99
  • 1
    In that response it explains that you need to cancel inside the 'onFetchProgress' event that fires periodically during an an asynchronous fetch. This looks promising, will try it later. Thanks. – Vector Feb 02 '12 at 18:49