#1 2022-07-19 19:15:54

steve888
Member
Registered: 2018-07-17
Posts: 8

TSQLDBServerHttpApi with tmThreadPool

I have noticed some problems with TSQLDBServerHttpApi when using a thread pool with TOleDBMSSQL2012ConnectionProperties.  The Ole CoUninit assertion seems to fail at times.

The Server runs in a Windows Service:

FProps := TOleDBMSSQL2012ConnectionProperties.Create('127.0.0.1\SQLEXPRESS','test','test','test');
FHttpServer := TSQLDBServerHttpApi.Create(FProps,'test',80,'test','test',False,64,nil,tmThreadPool);


The Client connection is created in a datamodule constructor and freed in the destructor:

http := TSQLDBWinHTTPConnectionProperties.Create(...)

statement := http.NewThreadSafeStatementPrepared(SomeSQL,True,True);

....parameter binding....

statement.ExecutePrepared;


Seeing this in the log at times:
20220715 06004760  ' ERROR "EAssertionFailed(125fef00)":"You should call TOleDBConnection.Free from the same thread which called its Create: i.e. call MyProps.EndCurrentThread from an THttpServerGeneric.OnHttpThreadTerminate event - see ticket 213544b2f5

Memory allocation seems to keep increasing over time because of this.  .  I tried using a HttpThreadTerminate event calling TSQLDBConnectionPropertiesThreadSafe(FProperties).EndCurrentThread, but the problem persists;  Please help.

Offline

#2 2022-07-20 06:51:26

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,534
Website

Re: TSQLDBServerHttpApi with tmThreadPool

Made your descendant of TSQLDBServerHttpApi to access protected FServer: THttpServerGeneric TSqlDBServerAbstract member.
Add FServer.OnHttpThreadTerminate handler, and inside added handles call Properties.EndCurrentThread
Pseudo-code:

  
FHttpServer.FServer.OnHttpThreadTerminate = function() begin Properties.EndCurrentThread; end;

As alternative - use an ODBC connection instead of OleDB

Last edited by mpv (2022-07-20 06:52:21)

Offline

#3 2022-07-20 08:35:45

radexpol
Member
From: Poland, Krk
Registered: 2019-11-29
Posts: 116

Re: TSQLDBServerHttpApi with tmThreadPool

  
FHttpServer.FServer.OnHttpThreadTerminate = function() begin Properties.EndCurrentThread; end;

Damn! After reading your post I was hoping that the newest delphi allows to implement anonymous event handlers, so I immediately tried it in my Alexandria smile Seems that we still have to wait for that extra feature.

Offline

#4 2022-07-20 08:53:48

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,534
Website

Re: TSQLDBServerHttpApi with tmThreadPool

No-no - this is preudo-code - just for simplicity smile
My main language currently is JS, so I wrote pseudo-code in JS way.

Offline

#5 2022-07-20 21:15:36

steve888
Member
Registered: 2018-07-17
Posts: 8

Re: TSQLDBServerHttpApi with tmThreadPool

mpv wrote:

Made your descendant of TSQLDBServerHttpApi to access protected FServer: THttpServerGeneric TSqlDBServerAbstract member.
Add FServer.OnHttpThreadTerminate handler, and inside added handles call Properties.EndCurrentThread
Pseudo-code:

  
FHttpServer.FServer.OnHttpThreadTerminate = function() begin Properties.EndCurrentThread; end;

As alternative - use an ODBC connection instead of OleDB


Thank you.  I will try that.

Offline

Board footer

Powered by FluxBB