我可以通过TADOConnection使用TEventDispatcher捕获SQL Server事件吗?

时间:2015-12-14 12:57:36

标签: c++ sql-server c++builder com+ adoconnection

我试图抓住TADOConnection上丢失的连接。 我已阅读thisthat文章

我已经实现了TEventDispatcher这样的课程。

#include <utilcls.h>
#include <ADOInt.hpp>

class EventHandler : public TEventDispatcher<EventHandler,&DIID_ConnectionEvents>
{
private:
  bool connected;
  TForm1 *theform;
  _Connection* server;
protected:
  HRESULT InvokeEvent(DISPID id, TVariant *params);
public:
  EventHandler();
  ~EventHandler();
  void Connect(TForm1 *form, _Connection* srv);
  void Disconnect();
};

EventHandler::EventHandler()
{
  connected = false;
  theform = NULL;
}

EventHandler::~EventHandler()
{
  if (connected)
    Disconnect();
}

实施

EventHandler *handler = new EventHandler();

HRESULT EventHandler::InvokeEvent(DISPID id, TVariant *params)
{
 String data = WideString(*params);
 ShowMessage("InvokeEvent : "+IntToStr(id)+" "+data);
}

void EventHandler::Connect(TForm1 *form, _Connection* srv)
{
  theform = form;

  server = srv;
  server->AddRef();
  ConnectEvents(server);
}

void EventHandler::Disconnect()
{
  DisconnectEvents(server);
  server->Release();
}

我试图像这样使用EventHandler类。

handler->Connect(this,ADOConnection1->ConnectionObject);

当sql server manual停止时,为什么不调用InvokeEvent类的EventHandler方法?

0 个答案:

没有答案