473,320 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

SP with no results throws ODBC exception in CRecordset

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::forwardOnly, 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!
Oct 20 '06 #1
1 1848
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
br**********************@hotmail.com
Remove only "_nos_pam"
Oct 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sean Anderson | last post by:
ODBC under System DSN Setup Access Driver give it the DSN (Data Source Name) MSA Click on Select and point to the myfile.mdb (your database file)
4
by: Mike van Engelen | last post by:
If I want to add a new derived class of the CRecordset type then it does not appear in the classes list, which I used to have before. The CDatabase class, for example, is available. Does anyone...
2
by: Dead-Cell | last post by:
The VC complier told me the RecordSet was read-only while I were trying to insert some record into database. My work environment is VC 6.0, SQL server and ODBC¡£ Please tell me, how to open a...
0
by: GS | last post by:
Hi Microsoft SQL Server 2000 - 8.00.760 (Intel X86) Dec 17 2002 14:22:05 Copyright (c) 1988-2003 Microsoft Corporation Desktop Engine on Windows NT 5.1 (Build 2600: Dodatek Service Pack. 1)...
0
by: Pavel Sorokin | last post by:
Hello, I created a table where a record consists of a single field of type lo. I'm trying to add a new record and store the contents of a file in it. However, when I call CRecordset.Update() I...
2
by: Thomas | last post by:
Hi, I wish to write an MFC application to access a PostGres database which will be implemented as a Snort Database. I'm wondering if it is possible to connect to the database using an ODBC...
2
by: bevis | last post by:
I'm new to sql server and mysql but this seems like it should be a pretty straight forward jdbc connection. But I have spent almost 2 days just trying to get a jdbc connection. Please help if you...
6
by: vaib | last post by:
hi to all. usenet is where i come back when i need some serious help. i have to do a project using c++ and sql , ie , i have to use odbc . the problem as always is of time . i use visual studio...
0
by: Chris Rebert | last post by:
On Wed, Nov 19, 2008 at 11:24 PM, Barak, Ron <Ron.Barak@lsi.comwrote: As I believe someone else pointed out recently in a extremely similar thread, GzipFile apparently doesn't check that the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.