לפתיחת קשר עם בסיס הנתונים
TypeError OpenDatabase() throw(std::exception) { HRESULT hr; IConnectionPointContainer *pCPC = NULL; IConnectionPoint *pCP = NULL; IUnknown *pUnk = NULL; int rc = 0; ::CoInitialize(NULL); errorCode = CREATE_INSTANCE; hr = pConn.CreateInstance(__uuidof(Connection)); if (FAILED(hr)) { fprintf (logIFP, "%s couldn't create connection instance\n", GetTime()); return CREATE_INSTANCE; } CreateInstance(TablePointer); errorCode = CONNECTION_EVENTS; hr = pConn->QueryInterface(__uuidof(IConnectionPointContainer),(void **)&pCPC); if (FAILED(hr)) { fprintf (logIFP, "%s couldn't create connection events\n", GetTime()); return CONNECTION_EVENTS; } hr = pCPC->FindConnectionPoint(__uuidof(ConnectionEvents), &pCP); pCPC->Release(); if (FAILED(hr)) { fprintf (logIFP, "%s couldn't create connection events\n", GetTime()); return CONNECTION_EVENTS; } errorCode = CONNECT_DATABASE; // here is the DSN connection. here the connection with specific database is made !! hr = pConn->Open("dsn=NAME;", "", "", adConnectUnspecified); if (FAILED(hr)) { fprintf (logIFP, "%s couldn't open database\n", GetTime()); throw std::exception(""); } errorCode = NO_ERR; return NO_ERR; }