views:

794

answers:

2

Already asked on the Evil Exchange, but as always that was no help. I'm having this problem today:

When creating a stand alone web application using IntraWeb, I get this exception in the IDE when I try to test out a session from my app in the browser:

First chance exception at $7C812A6B. Exception class EOleSysError with message 'CoInitialize has not been called'. Process WebContactManager.exe (1112)

If I click "continue" on the IDE exception dialog, the browser itself just shows:

200 OK

...rather than the controls on my main form.

This error does not seem to occur when I replace ADO with other database components such as dbExpress or BDE.

What is this error telling me, and how do I fix it?

(Note I'm using the stock "VCL for the Web" IntraWeb components which come built-in with D2007).

Thanks in advance for any and all help!

+2  A: 

Just found an answer to this here:

I found a more elegant solution as the whole problem originated from using Intraweb, I rather get Intraweb to initialise com for me. This sorts it out nicely.

When using your MS SQL DbExpress driver or ADO driver with Intraweb, you must set the ComInitialization property in the ServerController to ‘ciMultiThreaded’.

This will eliminates the "CoInitialize has not been called" error.

Jamo
+5  A: 

The "solution" provided in the link you quoted is basically wrong or at least incomplete. Only by setting ServerController.ComInitialization to ciMultiThreaded to true IW will gurantee that every thread will get COM initialized correctly. (for example think about Ajax callbacks)

If you create your own custom threads then you will have to call CoInitialize for that thread on your own though - as Intraweb does not know about your custom threads.

Olaf Monien
Olaf, thanks for the input. I don't see a place to set "clMultiThreaded to true" -- only a place to set ComInitialization to clMultiThreaded, clNone, or clNormal. Setting it to the former solve my immediate problem, which involved no custom threads. Point noted though on those (custom threads), and I did find some info on such cases, but still don't full understand when and where to call CoInitialize manually.
Jamo