473,569 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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::Ope n 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(CRecordse t::forwardOnly, cmd.c_str(), CRecordset::non e);
// 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_descr iption"), desc, SQL_C_TCHAR);
cr->GetFieldValue( _T("index_keys" ), keys, SQL_C_TCHAR);
MyIndex mi;
mi.Name = Util::SafeStr(n ame); // ignore nulls
mi.Keys = Util::SafeStr(k eys); // by converting them to empty string
mi.Description = Util::SafeStr(d esc);
cr->MoveNext();
}
catch (CDBException* ex) // Could be a real exception...
{ // Could be no results...
TCHAR s[1024];
ex->GetErrorMessag e(s, 1024, 0);
wcout << s << _T("\n");
ex->Delete();
}
cr->Close();
}

Any advice appreciated. Thanks!
Oct 20 '06 #1
1 1864
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::Ope n 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************* *********@hotma il.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
5202
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
1714
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 has any idea how this is possible? Of course I can make the class manually but I am too lazy for that.... Thanks for your replies! Mike
2
1129
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 CRecordSet. I am a new guy in this way.
0
1275
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) and MDAC2.8, VC7 -------------------------------------------------------------------------- CREATE PROCEDURE .
0
1027
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 get the following exception: "SetPos with data_at_exec not yet supported". My table doesn't get updated. Environment: PostgreSQL 7.4.1 on Cygwin,...
2
2668
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 driver, and then using CRecordset classes as one would when connecting to Access. I would appreciate any information or direction that can be provided in...
2
4534
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 can. I'm using Eclipse 3.2.2 and I have installed mysql-connector-java-5.0.6-bin.jar. I am trying to connect to SQL Enterprise Manager version 8.0...
6
289
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 c++ and am willing to use microsoft sql server ( any other wud also do fine and i can also use any other compiler of c++ ).but the problem is that i...
0
1252
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 underlying file is actually in gzip format until the .read() call, hence why its placement affects where the exception is thrown and thus how it's...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.