Re: CreateInstance on ado object returns 0x80080008

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



No, ADO is thread safe.

What is happening is COM is shutting down inside the process, and while COM
is shutting down you are trying to create a new COM object.

The COM sub-system realizes things are shutting down and returns the error.

So I suspect your issue with mismatched CoInitialize/CoUninitialize calls
was causing COM to unload, which in turn triggers the error.

Yes you have to be careful with CoInitialize/CoUninitialize and make sure
all calls match up exactly this can cause trouble.

--
Matt Neerincx [MSFT]

This posting is provided "AS IS", with no warranties, and confers no rights.

Please do not send email directly to this alias. This alias is for newsgroup
purposes only.

"Alan S" <AlanS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:262F9BD6-7EBD-4EC6-AEB9-678498030FE3@xxxxxxxxxxxxxxxx
> This is ado. Is ado not thread safe? Why would the ado connection object
> server be shutting down on this thread?.
>
> I have apparently cured the problem by moving my
> coinitialize/couninitialize
> calls to when the threads start and end. After generating a minidump at
> the
> site with the problem it appeared that a couninitialize call was being
> made
> with the comsvcs.dll unloaded causing a crash. I also create the
> connection
> object when I start the thread. This I hope forces the comsvcs and ado
> dlls
> to stay in memory.
>
>
>
> "Matt Neerincx [MSFT]" wrote:
>
>> This means CO_E_SERVER_STOPPING.
>>
>> So for example suppose someone is stopping your COM server while you are
>> trying to spin up more threads and create new COM threads, this could
>> happen.
>>
>> So best bet would be to exit the thread at this point so the service can
>> shut down.
>>
>> You could also set a flag when the service starts shutting down and check
>> this flag before spinning up more threads, etc...
>>
>> "Alan S" wrote:
>>
>> > The following code randomly returns a 0x80080008 error.
>> > Running in a thread in a service on WindowsXP SP2,
>> > The thread is started with AfxBeginThread.
>> > There are other threads running doing ADO com also.
>> >
>> > HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
>> >
>> > ADODB::_ConnectionPtr spConnection = NULL;
>> > ADODB::_CommandPtr spCommand = NULL;
>> > ADODB::_RecordsetPtr spRecordset = NULL;
>> > ADODB::_ParameterPtr spParameter = NULL;
>> >
>> > try{
>> > m_strDebug = _T("Create DB com:");
>> > _variant_t vPrimaryStudyDBKey;
>> >
>> > hr = spConnection.CreateInstance(__uuidof(ADODB::Connection));
>> > if(FAILED(hr)){
>> > CString strError;
>> > strError.Format(_T("Error creating connection hr = %x\n"), hr);
>> > LogError(strError);
>> > throw couldnotquerydatabase;
>> > }
>> >
>> >
>> > Any ideas as to why this would happen and how to prevent it.
>> >


.



Relevant Pages

  • Re: D5+ADO+Threads
    ... You will also need to call CoIntialize / ... >CoUninitialize in each thread. ... ADO is thread safe but that does not change the fact that you can't share ...
    (borland.public.delphi.database.ado)
  • Re: ADO thread safe?
    ... thread safe problems in a heavy loaded multi tier application. ... I'd like to have modal QuickReport previews. ... Is the ADO database driver thread safe ...
    (borland.public.delphi.database.ado)
  • Re: How to access MSSQL through ISAPI Filter?
    ... Kees de Winter schreef: ... you might have to call CoInitialize/CoUninitialize before/after using ADO ...
    (borland.public.delphi.database.ado)