Re: ADO in multithreaded: Application Verifier (with WinDbg) gives "Invalid Handle" at the end of my application

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Dvorak wrote on 27 Nov 2006 01:42:02 -0800:


Stephen Howe wrote:
The following is an excerpt from the code:
::Coinitialize(NULL)
Thank you for answer.
I changed the code. Now I'm using CoInitializeEx() instead of
Coinitialize(NULL):
HRESULT hr = CoInitializeEx(NULL,COINIT_MULTITHREADED); // setup
COM lib
if(FAILED(hr))
debug (" Multithread initialization failed");

The result is S_OK. Of course, the CoUninitialize() function remained
at the end of the thread function.
Invalid Handle doesn't appear at CoUninitialize() function on this
thread, but it appears at CoUnitialize() function from the main thread.
The application has a main thread where the same CoIntializeEx with the
same parameters as in code for the thread that I showed you is called.
Also, CoUninitialize() is called at the end of application on the same
main thread. So practically, instead of giving "Invalid Handle" at the
end of the thread on CoUninitialize(), now it gives at the end of
application on CoUninitialize().
CoInitializeEx isn't called on any other thread from this application.
I'll try to be as clear as possible. Here are somehow the steps for the
thread that uses ADO and the main thread which creats it:


Sorry if this sounds like a stupid suggestion, but did you switch ADO to
free-threaded? By default ADO is apartment-threaded (both-threaded), so
calls will be serialized - this is so that it can support Access/Jet which
uses a single-threaded driver. You can change ADO to free-threaded by
editing the registry, you do this using the ADOFre15.reg file located in the
C:\Program Files\Common Files\System\ADO folder.

If the database you are connecting to has a driver that support connection
pooling then trying to share a connection via threads may well result in
slower performance. It's also possible that the connection could be dropped
or the link to the server broken in some way, so you'll need to make sure
you handle this possibility too.

Dan


.



Relevant Pages

  • Re: MTA with Thread Pool API
    ... process holds on to it's own connection object, ... my question is related to CoInitializeEx/ CoUninitialize() ... Storage, I can flag whether or not the thread has called CoInitializeEx, ... some way that I can use the thread pool API? ...
    (microsoft.public.win32.programmer.kernel)
  • Re: C++ support for ADO
    ... TESTHR(pConn.CreateInstance(__uuidof(Connection))); ... In answer to your question I'm interested in ADO not the ADO.net. ... data classes for working with ADO/OLE DB. ... You can also use the OLE SDK. ...
    (microsoft.public.data.ado)
  • Re: ODBC/OLE DB Connection Pool
    ... > connection be kept open for the application as this will serialize all ... threads ONCE they are returned to the pool. ... > Tips for ADO Users ... > The ADO Connection object implicitly uses IDataInitialize. ...
    (microsoft.public.inetserver.asp.db)
  • Re: ODBC/OLE DB Connection Pool
    ... > connection be kept open for the application as this will serialize all ... threads ONCE they are returned to the pool. ... > Tips for ADO Users ... > The ADO Connection object implicitly uses IDataInitialize. ...
    (microsoft.public.data.oledb)
  • Re: How to make the app run?????
    ... throwing an error if the connection never was opened, ... How can i tell if i'm using ADO as in VB or .Net ADO ?? ... First of all, it was not shown to my customer, I took it to a very nice ... How do you get in "installed" on client computer? ...
    (microsoft.public.dotnet.general)