Wombat
September 23rd, 2009, 03:00 AM
Hi guys,
CString GetQueryValue(CString strConnectionString, CString strQuery)
{
CString strResult;
CoInitialize(NULL);
try
{
_ConnectionPtr cn("ADODB.Connection");
_RecordsetPtr rs("ADODB.Recordset");
_bstr_t strMissing(L"");
cn->Open(strConnectionString.AllocSysString(), strMissing, "", adConnectUnspecified);
rs->Open(strQuery.AllocSysString(), _variant_t((IDispatch *) cn, true), adOpenKeyset, adLockOptimistic, adCmdText);
if (!rs->EndOfFile)
{
_variant_t vtValue;
vtValue.vt = VT_NULL||VT_BSTR||VT_EMPTY;
vtValue = rs->Fields->Item[(long) 0]->Value;
if (vtValue.vt == VT_NULL)
{
strResult = L"";
}
else
{
strResult.Format(L"%s", (WCHAR*) ((_bstr_t) vtValue));
}
}
else
{
strResult = L"";
}
rs->Close();
cn->Close();
rs = NULL;
cn = NULL;
return strResult;
}
catch (_com_error &e)
{
CString szError;
szError.Format(L"Recordset error: %s", (WCHAR*) e.Description());
DumpLog(szError);
szError.Format(L"Query was: %s", strQuery);
DumpLog(szError);
return L"";
}
::CoUninitialize();
}
I use the above codes to send queries to an oracle database. But I received an exception "Recordset error: Error while trying to retrieve text for error ORA-01019".
Can anyone shed some lights on what could be the problem and how to resolve?
CString GetQueryValue(CString strConnectionString, CString strQuery)
{
CString strResult;
CoInitialize(NULL);
try
{
_ConnectionPtr cn("ADODB.Connection");
_RecordsetPtr rs("ADODB.Recordset");
_bstr_t strMissing(L"");
cn->Open(strConnectionString.AllocSysString(), strMissing, "", adConnectUnspecified);
rs->Open(strQuery.AllocSysString(), _variant_t((IDispatch *) cn, true), adOpenKeyset, adLockOptimistic, adCmdText);
if (!rs->EndOfFile)
{
_variant_t vtValue;
vtValue.vt = VT_NULL||VT_BSTR||VT_EMPTY;
vtValue = rs->Fields->Item[(long) 0]->Value;
if (vtValue.vt == VT_NULL)
{
strResult = L"";
}
else
{
strResult.Format(L"%s", (WCHAR*) ((_bstr_t) vtValue));
}
}
else
{
strResult = L"";
}
rs->Close();
cn->Close();
rs = NULL;
cn = NULL;
return strResult;
}
catch (_com_error &e)
{
CString szError;
szError.Format(L"Recordset error: %s", (WCHAR*) e.Description());
DumpLog(szError);
szError.Format(L"Query was: %s", strQuery);
DumpLog(szError);
return L"";
}
::CoUninitialize();
}
I use the above codes to send queries to an oracle database. But I received an exception "Recordset error: Error while trying to retrieve text for error ORA-01019".
Can anyone shed some lights on what could be the problem and how to resolve?