ADO in multithreaded: Application Verifier (with WinDbg) gives "Invalid Handle" at the end of my application
- From: "Dvorak" <goran1978@xxxxxxxxx>
- Date: 24 Nov 2006 09:22:25 -0800
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!
.
- Follow-Ups:
- Prev by Date: How to read binary data into a varchar(80) Dbase File
- Next by Date: Re: ADO in multithreaded: Application Verifier (with WinDbg) gives "Invalid Handle" at the end of my application
- Previous by thread: How to read binary data into a varchar(80) Dbase File
- Next by thread: Re: ADO in multithreaded: Application Verifier (with WinDbg) gives "Invalid Handle" at the end of my application
- Index(es):
Relevant Pages
|
|