DataSnap WebBroker application, "Coinitialize has not been called"

384 views Asked by At

Delphi 10.3

I have a Datasnap Webbroker application that has been running fine for 6 months. Now it responds to requests with "coinitialize has not been called". It is the same exe. I don't think there have been any changes to the machine it is running on or the SQL machine it is connecting to. We've tried adding coinitialize calls at various places in the code, but that has not prevented the error.

I'm not sure what to try next. Thank you.

1

There are 1 answers

0
George Wynne On

I found an expert who solved it. Thank you, Olaf Monien.

We're still unclear as to how this project worked for so long without this code and then suddenly stopped working.

uses Winapi.ActiveX...

constructor TWebMod.Create(AOwner: TComponent);
begin
  //om: make sure Coinitialize get called *before* any ADO component is created
  //Important: in Webbroker, *every* request creates its own instance of TWebMod - in a worker thread!
  //During construction ADO components are created, which will lead to an error,
  // if done in a worker thread - if CoInitialize is NOT called before.
  CoInitializeEx(nil, Coinit_multithreaded);
  inherited;
end;

destructor TWebMod.Destroy;
begin
  inherited;
  CoUninitialize;  //om: uninitialize when done
end;