#1 2020-06-28 15:21:42

cregonat
Member
Registered: 2020-04-27
Posts: 7

call TOleDBConnection.Free from the same thread...

Hi,

I'm getting an EAssertionFailed: "You should call TOleDBConnection.Free from the same thread which....".  As it's stated on the documentation, I've implemented the OnHttpThreadTerminate event:

  HttpServer.OnHttpThreadTerminate := FOnThreadTerminate;

then,

procedure THTTPTerminals.FOnThreadTerminate(sender: TThread);
begin
   FDBMain.ConProp.EndCurrentThread;
   FDBProd.ConProp.EndCurrentThread;
end

the strange behaviour is that if I call the server, it works without any trouble, but, if I left the server running without making any call for some time, then, the first call after that pause throws that assertion, and subsecuents calls works without throwing that assertion.

probably I should say that I've to extend a legacy system which has two databases. I know that this isn't an ideal situation, but, it what i have. So, i'm using two connections, each one with his own model.

Thanks

Last edited by cregonat (2020-06-28 15:29:33)

Offline

#2 2020-06-29 06:42:40

igors233
Member
Registered: 2012-09-10
Posts: 241

Re: call TOleDBConnection.Free from the same thread...

It could be that DB itself or OLE terminates connection after inactivity and then when you try to call it it raises exception and next one get's a new connection established.
You can try to  configure ConnectionTimeOutMinutes on your OleDB connection properties.

Offline

#3 2020-06-29 07:50:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: call TOleDBConnection.Free from the same thread...

How is ConProp defined? Is it a property?
If it is a local variable, then the connection may have been freed in-between so the instance stored in your variable is invalid.

Please don't store the connection instance, but retrieve it in the beginning of each method using TSQLDBConnectionProperties.ThreadSafeConnection, or by using TSQLDBConnectionProperties.NewThreadSafeStatement/NewThreadSafeStatementPrepared.

Offline

Board footer

Powered by FluxBB