ADO & events in ATL 
Author Message
 ADO & events in ATL

Hello to everyone,

I am trying to make events of ADO work implementing a sink in C++.
I have found many articles on the Internet but they have only confused me
instead of giving me an answer.

I am using the #import statement to import the ADO DLL.
I have followed the implementation of the article "ADO Events Model Example"
in the MSDN, and I can't seem to be able to fire the ExecuteComplete event.

*** Other events fire normally. ***

The WillExecute event fires normally also.
The ExecuteComplete event doesn't seem to fire though :(
Actually it fires just before my thread exits (!?)

The sink implementation is the following:

class CConnEvent : public ConnectionEventsVt
{
private:
      ULONG   m_cRef;
   public:
      CConnEvent() { m_cRef = 0; };
      ~CConnEvent() {};

      STDMETHODIMP QueryInterface(REFIID riid, void ** ppv);
      STDMETHODIMP_(ULONG) AddRef(void);
      STDMETHODIMP_(ULONG) Release(void);

      STDMETHODIMP raw_InfoMessage(
         struct Error *pError,
         EventStatusEnum *adStatus,
         struct _Connection *pConnection);

      STDMETHODIMP raw_BeginTransComplete(
         LONG TransactionLevel,
         struct Error *pError,
         EventStatusEnum *adStatus,
         struct _Connection *pConnection);

      STDMETHODIMP raw_CommitTransComplete(
         struct Error *pError,
         EventStatusEnum *adStatus,
         struct _Connection *pConnection);

      STDMETHODIMP raw_RollbackTransComplete(
         struct Error *pError,
         EventStatusEnum *adStatus,
         struct _Connection *pConnection);

      STDMETHODIMP raw_WillExecute(
         BSTR *Source,
         CursorTypeEnum *CursorType,
         LockTypeEnum *LockType,
         long *Options,
         EventStatusEnum *adStatus,
         struct _Command *pCommand,
         struct _Recordset *pRecordset,
         struct _Connection *pConnection);

      STDMETHODIMP raw_ExecuteComplete(
         LONG RecordsAffected,
         struct Error *pError,
         EventStatusEnum *adStatus,
         struct _Command *pCommand,
         struct _Recordset *pRecordset,
         struct _Connection *pConnection);

      STDMETHODIMP raw_WillConnect(
         BSTR *ConnectionString,
         BSTR *UserID,
         BSTR *Password,
         long *Options,
         EventStatusEnum *adStatus,
         struct _Connection *pConnection);

      STDMETHODIMP raw_ConnectComplete(
         struct Error *pError,
         EventStatusEnum *adStatus,
         struct _Connection *pConnection);

      STDMETHODIMP raw_Disconnect(
         EventStatusEnum *adStatus,
         struct _Connection *pConnection);

Quote:
};

Everything is implemented as the article says.
Is there any requirement that I implement a message loop to be able to get
the COM call? I am using a MTA model and I don't have a message loop... Is
this the reason? If so, how come the other events fire normally?!

If anyone knows the answer or has the faintest idea of what is going on
here, please drop a line!

Thanks!

Jason



Sun, 22 Feb 2004 22:28:07 GMT  
 ADO & events in ATL
Hi Jaspn


Quote:
> Hello to everyone,

> I am trying to make events of ADO work implementing a sink in C++.
> I have found many articles on the Internet but they have only confused me
> instead of giving me an answer.

> I am using the #import statement to import the ADO DLL.
> I have followed the implementation of the article "ADO Events Model
Example"
> in the MSDN, and I can't seem to be able to fire the ExecuteComplete
event.

> *** Other events fire normally. ***

I had also such a problem with ADO. In my case I tried to catch
FetchComplete
and I never received it. But when I start catching FetchProgress and catched
them
all, I finnaly also receive the FetchComplete Event.

Maybe this helps you.....

Sebastian



Mon, 23 Feb 2004 15:27:39 GMT  
 ADO & events in ATL
I ported my class to MFC and it works. The ExecuteComplete event fires
normally.
I am beginning to think that this is actually a threading problem.

The call of _ConnectionPtr::Execute(, , adAsyncExecute) is made from a
worker thread, which then sleeps and waits for a next execution request. The
question therefore is: WHICH is the thread that is supposed to receive the
event? Is it a ADO thread? Is it my _main_ thread?
Is there a problem with the model I use? I don't think so cause the same
happens when I call from an STA too.
You know what is the weirdest thing in all this?
***The events I don't receive, _get_ called when the _ConnectionPtr gets
closed!!!***
The are queued somewhere and COM sends them to me all together the minute I
call m_pConn->Close() !!!
I am totally baffled here...

Jason

............................................................................

Quote:
>          struct _Connection *pConnection);

>       STDMETHODIMP raw_Disconnect(
>          EventStatusEnum *adStatus,
>          struct _Connection *pConnection);
> };

> Everything is implemented as the article says.
> Is there any requirement that I implement a message loop to be able to get
> the COM call? I am using a MTA model and I don't have a message loop... Is
> this the reason? If so, how come the other events fire normally?!

> If anyone knows the answer or has the faintest idea of what is going on
> here, please drop a line!

> Thanks!

> Jason



Mon, 23 Feb 2004 18:39:07 GMT  
 ADO & events in ATL
Unbelievable:

I added a

MSG msg;
GetMessage(&msg, 0, 0, 0);
DispatchMessage(&msg);

set of commands and I received the event!
COM tries to make the event call through a thread/windows message. Event if
I don't use an STA model, this doesn't change!
Can anyone figure out why no marshalling was needed for my event sink
pointer to be used from ADO like that?

Jason Orphanidis


Quote:
> I ported my class to MFC and it works. The ExecuteComplete event fires
> normally.
> I am beginning to think that this is actually a threading problem.

> The call of _ConnectionPtr::Execute(, , adAsyncExecute) is made from a
> worker thread, which then sleeps and waits for a next execution request.
The
> question therefore is: WHICH is the thread that is supposed to receive the
> event? Is it a ADO thread? Is it my _main_ thread?
> Is there a problem with the model I use? I don't think so cause the same
> happens when I call from an STA too.
> You know what is the weirdest thing in all this?
> ***The events I don't receive, _get_ called when the _ConnectionPtr gets
> closed!!!***
> The are queued somewhere and COM sends them to me all together the minute
I
> call m_pConn->Close() !!!
> I am totally baffled here...

> Jason

............................................................................

- Show quoted text -

Quote:
> >          struct _Connection *pConnection);

> >       STDMETHODIMP raw_Disconnect(
> >          EventStatusEnum *adStatus,
> >          struct _Connection *pConnection);
> > };

> > Everything is implemented as the article says.
> > Is there any requirement that I implement a message loop to be able to
get
> > the COM call? I am using a MTA model and I don't have a message loop...
Is
> > this the reason? If so, how come the other events fire normally?!

> > If anyone knows the answer or has the faintest idea of what is going on
> > here, please drop a line!

> > Thanks!

> > Jason



Tue, 24 Feb 2004 14:25:03 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. #import, ATL & Events

2. ADO In ATL Project,ADO Version,CreateInstance Failed

3. ATL DLL event sink with a VB ActiveX DLL event source

4. ATL COM Component firing events into VBScript event sink

5. Problem with ATL Sink class for catching another ATL's events

6. How to do this in ATL - raise event from a class function in ATL server

7. Events && Delegates

8. ATL Control & ATL Web Service

9. mixing ATL & Non ATL code

10. Help with ADO 2.7 (Event)

11. ADO connection.open events

12. Chalenging question on ADO and events

 

 
Powered by phpBB® Forum Software