Click to See Complete Forum and Search --> : Failure from another thread: conn->CreateInstance( __uuidof( ADODB::Connection ) );


alexiworld
July 8th, 2003, 09:33 AM
I have a problem with ADO connections ...

When I try to create connection through ADO to database through GUI thread of my dialog I don't have any problem. The connections are properly created and I can use them.

But If I start new thread and delegate it creating of connections then I received failed HRESULT from CreateInstance.
I step into comip.h and I found that it result in errors here:
hr = CoCreateInstance(rclsid, pOuter, dwClsContext, __uuidof(IUnknown), reinterpret_cast<void**>(&pIUnknown));

Can somebody give me advice what I should do?? And what cause this problem? Thank you in advance!

Regards, Alex

antares686
July 9th, 2003, 06:34 AM
How are you creating your thread and can you post the comip.h file for review. Also, it may be more appropriate to post in the C++ section as oppossed to here.

alexiworld
July 9th, 2003, 07:27 AM
antares686,
I created thread as usual.

UINT ReportThreadProc( LPVOID pParam ) { ... }
AfxBeginThread(ReportThreadProc, this);

I tried to use CreateThread() also. But nothing happend. The problem is still there.

I'll post this in some other group also. I relied that somebody from database will be able to answer me.

Regards, Alex

alexiworld
July 9th, 2003, 09:04 AM
I decided to look for the problem in google and there I realized that COM must be initialized per thread. So I call ::CoInitialize(NULL); in the begging of the thread and every thing is going fine.

Regards,
Alex