|
Home > Archive > MS SQL Server ODBC > October 2006 > SP with no results throws ODBC exception in CRecordset
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
SP with no results throws ODBC exception in CRecordset
|
|
| Mike C# 2006-10-24, 6:40 pm |
| Hi all,
I'm writing a little app that uses ODBC to call a SQL 2K stored procedure
several times in a loop, with a different parameter each time. The SP can
return no results in some instances. When no results are returned, the
CRecordset throws an exception. I've tracked the problem down to
dbcore.cpp, where the CRecordset::Open method performs a MoveNext() after
executing the SP (it apparently doesn't bother checking that any results
were actually returned). It works fine as long as at least one row is
returned, otherwise a CBDException is thrown. Does anyone know if there is
a better solution than wrapping my code in a try...catch and ignoring the
CDBException? Here's a snippet of my code:
cmd = _T("{CALL [") + strDatabaseName +
_T("]..sp_helpindex ('") + strTableName + _T("')}");
cr = new CRecordset(this); // 'this' is a class that inherits from CDatabase
try // Right now I'm handling the exception by ignoring it...
{
cr-> Open(CRecordset::for
wardOnly, cmd.c_str(), CRecordset::none);
// Retrieve the results
while (!cr->IsEOF()) // Loop through them
{
CDBVariant name, desc, keys;
cr->GetFieldValue(_T("index_name"), name, SQL_C_TCHAR);
cr->GetFieldValue(_T("index_description"), desc, SQL_C_TCHAR);
cr->GetFieldValue(_T("index_keys"), keys, SQL_C_TCHAR);
MyIndex mi;
mi.Name = Util::SafeStr(name);
// ignore nulls
mi.Keys = Util::SafeStr(keys);
// by converting them to empty string
mi.Description = Util::SafeStr(desc);
cr->MoveNext();
}
catch (CDBException* ex) // Could be a real exception...
{ // Could be no results...
TCHAR s[1024];
ex->GetErrorMessage(s, 1024, 0);
wcout << s << _T("\n");
ex->Delete();
}
cr->Close();
}
Any advice appreciated. Thanks!
| |
| Bruno van Dooren [MVP VC++] 2006-10-24, 6:40 pm |
| > I'm writing a little app that uses ODBC to call a SQL 2K stored procedure
> several times in a loop, with a different parameter each time. The SP can
> return no results in some instances. When no results are returned, the
> CRecordset throws an exception. I've tracked the problem down to
> dbcore.cpp, where the CRecordset::Open method performs a MoveNext() after
> executing the SP (it apparently doesn't bother checking that any results
> were actually returned). It works fine as long as at least one row is
> returned, otherwise a CBDException is thrown. Does anyone know if there
> is a better solution than wrapping my code in a try...catch and ignoring
> the CDBException? Here's a snippet of my code:
Looking at the implementation of Move, and MSDN, it seems that this is by
design.
But if you want to know for sure, try asking in the DAO or MFC newsgroups.
--
Kind regards,
Bruno van Dooren
bruno_nos_pam_van_do
oren@hotmail.com
Remove only "_nos_pam"
|
|
|
|
|