Open database asynchronously in C++
Hi all,
I am struggling with this for several days now, so I hope someone can help
me out.
I want to open a database in asynchronous mode, so my (C++) code looks like
this:
CDBPropSet dbinit(DBPROPSET_DBINIT);
dbinit.AddProperty(DBPROP_INIT_DATASOURCE, "MyDataSource");
dbinit.AddProperty(DBPROP_AUTH_USERID, "MyUserId");
dbinit.AddProperty(DBPROP_AUTH_PASSWORD, "MyPassword");
dbinit.AddProperty(DBPROP_INIT_CATALOG, "MyCatalog");
dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)DBPROMPT_NOPROMPT);
dbinit.AddProperty(DBPROP_INIT_TIMEOUT, (short)20);
dbinit.AddProperty(DBPROP_INIT_GENERALTIMEOUT, (short)20);
dbinit.AddProperty(DBPROP_INIT_ASYNCH, DBPROPVAL_ASYNCH_INITIALIZE);
HRESULT hr = MyDataSource.Open("SQLNCLI10", &dbinit);
if (SUCCEEDED(hr))
{
. . .
}
The 'Open' function returns 'DB_S_ASYNCHRONOUS' which is ok. But now my
problem arises: how do I implement the callback so I know when opening the
database has finished.
I know I have to implement the 'IDBAsynchNotify' interface
(http://msdn.microsoft.com/en-us/library/ms718270(VS.85).aspx), but it does
not work for me; most probably because I am not doing it the right way. I
hope someone can provide me some C++ code how to do this, as I have been
searching the internet for hours now, without any success.
Thanks,
Robby