In my project I want to export an ado connection interface and use it.
The code like this:
STDMETHODIMP CDBInterface::OpenDBConnect(IDispatch **pConnect)
{
_ConnectionPtr pConn;
if (OpenDBConnection(pConn))
{
*pConnect = (IDispatch*)pConn;
pConn->AddRef();
return S_OK;
}else{
return E_FAIL;
}
}
STDMETHODIMP CDBInterface::SQLQueryWitchConn(BSTR sql, IDispatch *pConnect,
IATLRecordset **pRecordSet)
{
CComObject<CATLRecordset>* pClsRecordset = NULL;
HRESULT hr = CComObject<CATLRecordset>::CreateInstance(&pClsRecordset);
if (SUCCEEDED(hr))
{
try{
_ConnectionPtr ptrConn(pConnect);
...
}catch(_com_error& COMErr){
Error((char*)(COMErr.Description()));
hr = E_FAIL;
}
}
return hr;
}
But av exception occurs when I try to create an _ConnectionPtr with returned
IDispatch interface. How can I fix this problem?
Thanks in advanced.
What is the bigger goal here? Generally speaking, database connections
should be opened late and closed early. They cannot be passed from one
application to another (if that is what you are contemplating).
"bucher" <buc...@xxx.com> wrote in message
news:u5Z49Ewb...@TK2MSFTNGP02.phx.gbl...