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



Good day/evening Mrs/Ms
I hope that this is the proper group for a question like this.
Problem: I'm using ADO to connect to SQL Server in a multithreaded
application. A thread that reads/writes in SQL Server is created from
the main thread. In fact, I removed the writing/reading to/from
database part, and I let only the connection and disconnection part.
The following is an excerpt from the code:
::Coinitialize(NULL)
try
{
_ConnectionPtr adoConnection;
hr = adoConnection.CreateInstance( __uuidof( Connection ) );
if(SUCCEEDED(hr))
{
adoConnection->ConnectionString = pszConnectString;
adoConnection->CursorLocation = adUseClient;
//TODO: m_pConnection->ConnectionTimeout = ....
hr = adoConnection->Open("", "", "", adModeUnknown);
//TODO: removed write/read, add this later after Invalid
handle problem is solved
Sleep(1000);
adoConnection->Close();
adoConnection.Release();
}
}
catch( _com_error &e )
{
// Get info from _com_error
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
char pszErrorCode[2500];
int nSize = 0;
nSize = sprintf(pszErrorCode, "(ADO) : Exception thrown for classes
generated by #import" );
nSize+= sprintf(pszErrorCode + nSize, "\tCode = %08lx\n", e.Error());
nSize+= sprintf(pszErrorCode + nSize, "\tCode meaning = %s\n",
e.ErrorMessage());
nSize+= sprintf(pszErrorCode + nSize, "\tSource = %s\n", (LPCTSTR)
bstrSource);
nSize+= sprintf(pszErrorCode + nSize, "\tDescription = %s\n",
(LPCTSTR) bstrDescription);
debug(pszErrorCode);
::CoUninitialize();
return false;
}
::CoUninitialize();
return true;

All is running ok. But, an error "Invalid handle exception for current
stack trace. " is given when I'm testing my application with
Application Verifier and WinDbg tool. I observed that when Open
function from ADO is appelead, msado15.dll is loaded (and of course,
all the other dll's that msado15.dll uses). There aren't any errors if
this code does not run (thus msado15.dll is not loaded). And there are
other threads running. So the problem is clearly from this part. The
same situation appears in testing both cases release and debug
versions.
I'm sure that I'm missing something, but I can't see what! And it's
been 2 days since I'm trying to resolve this. I searched all over the
net, but I still can't find something similar to my case.
Thanks a lot for any help!

.



Relevant Pages

  • Re: How to Mimic Access Externally Linked Tables using ADO?
    ... > using SQL Server for efficiency reasons. ... > connection up programmatically using ADO or ADOX or some SQL Server API? ... >> newsgroup, but if you have a good reason to send me e-mail, you'll find ... ADO does not have a query engine. ...
    (microsoft.public.data.ado)
  • Re: How to access the SQL server express from mfc application?
    ... There are different ways to do this via MFC. ... You could certainly try ADO, ... the entire contents of the database to a SQL Server Standard Server. ...
    (microsoft.public.vc.mfc)
  • Re: DAO vs ADO
    ... and ADO when working with SQL Server data. ... which makes DAO a good choice. ... > add additional overhead by loading Jet, ...
    (microsoft.public.access.conversion)
  • Re: DAO vs ADO
    ... and ADO when working with SQL Server data. ... which makes DAO a good choice. ... > add additional overhead by loading Jet, ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Text of Startup Option Application Title
    ... This is a quote from Mary Chipman, SQL Server MVP, ex-Access MVP, and author ... DAO was designed, customized, and tweaked specifically for the Jet ... ADO was designed as a general-purpose data access wrapper around OLE ...
    (microsoft.public.access.formscoding)