CoInitialize error working with database inside threads CoInitialize error working with database inside threads database database

CoInitialize error working with database inside threads


@mjn: I'm not allowed to comment your remark in the previous answer, so I created a new answer: calling CoInitialize from the constructor is one of typical error programmers do.

Constructor is executed in a context of another thread, but you need to initialize COM on the current thread (when a thread procedure is running i.e. as part of Execute method) see


procedure TYourThread.execute;begin  CoInitialize(nil);   FConnection:=TConnection.Create(...);  try    ThreadCode ....  finally    FConnection.free;    CoUninitialize;  end;end;


Another cause is that Application.Initialize; is missing or commented out in the main application DPR.