danny77uk
September 11th, 2007, 07:51 AM
I've got a try-catch block around some vanilla ADO code. If there is an error, the code in the catch block gets an error string from the resource file and puts in in a dialog. But for reasons I can't explain, the resource-load always fails during an actual error.
static CString errorStr; // global
...
errorStr.LoadString(IDS_ERR_QRY_EXECUTE_NONPROC_STR); // works fine
try
{
m_pCmd->CommandText = (_bstr_t)strQry;
if (m_bRecordSet)
{
m_pRs.CreateInstance(__uuidof(Recordset));
m_pRs = m_pCmd->Execute(NULL,NULL,adCmdText);
}
else {
m_pCmd->Execute(NULL,NULL,adCmdText|adExecuteNoRecords);
}
}
catch(_com_error &e)
{
errorStr.LoadString(IDS_ERR_QRY_EXECUTE_NONPROC_STR); // empty?!
ErrUtils::errMsg(errorStr, e.ErrorMessage(); // just calls MessageBox
}
The resource exists and the call to loadstring works fine outside the block. Any ideas why this could be happening? I've also tried creating a temporary string in the block (static and non-static). Hard-coded text works fine.
Any help appreciated!
static CString errorStr; // global
...
errorStr.LoadString(IDS_ERR_QRY_EXECUTE_NONPROC_STR); // works fine
try
{
m_pCmd->CommandText = (_bstr_t)strQry;
if (m_bRecordSet)
{
m_pRs.CreateInstance(__uuidof(Recordset));
m_pRs = m_pCmd->Execute(NULL,NULL,adCmdText);
}
else {
m_pCmd->Execute(NULL,NULL,adCmdText|adExecuteNoRecords);
}
}
catch(_com_error &e)
{
errorStr.LoadString(IDS_ERR_QRY_EXECUTE_NONPROC_STR); // empty?!
ErrUtils::errMsg(errorStr, e.ErrorMessage(); // just calls MessageBox
}
The resource exists and the call to loadstring works fine outside the block. Any ideas why this could be happening? I've also tried creating a temporary string in the block (static and non-static). Hard-coded text works fine.
Any help appreciated!