2

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.

  • "*coinitialize is not found*" - are you sure that is the *exact* error message? Not "CoInitialize has not been called" instead? – Remy Lebeau Jul 01 '21 at 15:07
  • sorry - yes, "coinitialize has not been called" is what I am getting – George Wynne Jul 01 '21 at 15:08
  • 1
    @GeorgeWynne When your question is not correct, you really must [edit](https://stackoverflow.com/posts/68212280/edit) it instead of mentioning the error in a comment. – fpiette Jul 01 '21 at 15:10
  • Maybe an update in a DLL your application calls now require a call to CoInitialize? Using the debugger, you may probably found where this error is triggered. – fpiette Jul 01 '21 at 15:13
  • I don't think there have been any changes to DLLs. It looks like the error is firing sometime before the webmodulebeforedispatch event but I have not been have to run it with the debugger yet. – George Wynne Jul 01 '21 at 15:46
  • I meant an update not in your application but a DLL used by the application. For example in the SQL driver or a component you use. – fpiette Jul 01 '21 at 15:48
  • I don't think so. – George Wynne Jul 01 '21 at 16:02
  • Do some debugging. Guessing won't get you far. – David Heffernan Jul 01 '21 at 18:36

1 Answers1

0

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;