Unix Technical Forum

CRecordset.Close() causes exception

This is a discussion on CRecordset.Close() causes exception within the MS SQL ODBC forums, part of the Microsoft SQL Server category; --> Hi, I'm having problems with VC++ 6.0 reading an Access 2000 database. CRecordset::Close() throws an exception. I've created a ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > MS SQL ODBC

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 08:44 PM
Jezzer
 
Posts: n/a
Default CRecordset.Close() causes exception

Hi,

I'm having problems with VC++ 6.0 reading an Access 2000 database.
CRecordset::Close() throws an exception. I've created a simple test
dialog which does an open and close of a CRecordset. The database has
one table called 'Addresses' in it. The CAddressSet was created by the
Class Wizard.

void CDatabaseDlg::OnOK()
{
CDatabase db;

db.Open(NULL,FALSE,FALSE,"DSN=c:\\dev\\db1.mdb");

// Construct the snapshot object
CAddressSet rsAddr( NULL );

// Set options if desired, then open the recordset
rsAddr.Open(CRecordset::snapshot, NULL, CRecordset::none );


rsAddr.Close( );
db.Close( );


Dialog::OnOK();
}

The Close method throws on the AFX_SQP_SERVER line below:

RETCODE nRetCode;
if (m_hstmt != SQL_NULL_HSTMT)
{
AFX_SQL_SYNC(::SQLFreeStmt(m_hstmt, SQL_DROP));
m_hstmt = SQL_NULL_HSTMT;
}

This program just couldn't get any simpler - and yet it doesn't work!
Anybody got any clue as to why????

Many thanks,

Jeremy

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 08:44 PM
Baxter
 
Posts: n/a
Default Re: CRecordset.Close() causes exception

Recordset is not connected to database? Recordset is completely empty?
etc?

--
-------------------------------------------------------------------------
Free software - Baxter Codeworks www.baxcode.com
-------------------------------------------------------------------------


"Jezzer" <Jemtaylor@yahoo.com> wrote in message
news:1115894836.839503.104060@g14g2000cwa.googlegr oups.com...
> Hi,
>
> I'm having problems with VC++ 6.0 reading an Access 2000 database.
> CRecordset::Close() throws an exception. I've created a simple test
> dialog which does an open and close of a CRecordset. The database has
> one table called 'Addresses' in it. The CAddressSet was created by the
> Class Wizard.
>
> void CDatabaseDlg::OnOK()
> {
> CDatabase db;
>
> db.Open(NULL,FALSE,FALSE,"DSN=c:\\dev\\db1.mdb");
>
> // Construct the snapshot object
> CAddressSet rsAddr( NULL );
>
> // Set options if desired, then open the recordset
> rsAddr.Open(CRecordset::snapshot, NULL, CRecordset::none );
>
>
> rsAddr.Close( );
> db.Close( );
>
>
> Dialog::OnOK();
> }
>
> The Close method throws on the AFX_SQP_SERVER line below:
>
> RETCODE nRetCode;
> if (m_hstmt != SQL_NULL_HSTMT)
> {
> AFX_SQL_SYNC(::SQLFreeStmt(m_hstmt, SQL_DROP));
> m_hstmt = SQL_NULL_HSTMT;
> }
>
> This program just couldn't get any simpler - and yet it doesn't work!
> Anybody got any clue as to why????
>
> Many thanks,
>
> Jeremy
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 08:44 PM
Jezzer
 
Posts: n/a
Default Re: CRecordset.Close() causes exception

Yes, I see why it might look like that with the NULL in the CRecordSet
declaration. I've defined my test database using ODBC manager and the
GetDefaultConnect() method looks like this:

CString CAddressSet::GetDefaultConnect()
{
return _T("ODBC;DSN=db1");
}

where 'db1' is my database with the Addresses table in it. This was all
put there by the wizard.
I have had this same test retrieving the data succesfully but I took
that stuff out to make the example less cluttered.

It's just the Close that crashes whether you retrieve stuff or not.

cheers anyway....

Jeremy

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 08:45 PM
Jezzer
 
Posts: n/a
Default Re: CRecordset.Close() causes exception

Hi all,

I've made some progress with this problem now. I've discovered that
CRecordSet::Close() only crashes when running under Visual Studio -
when the exe is run stand-alone it works fine. I can remove the 'fudge'
and it loads the DB Ok.

The 'fudge' I use where I set m_hstmnt = SQL_NULL_HSTMT in the
::Close() method means that when debugging the method does not crash -
but it seems to cause the Access interface to run *extremely* slowly.
No CPU being used - just seems to be waiting an awful lot. So I suspect
that whatever is being freed by the 'SQLFreeStmt' call is getting
clogged. My hunch is that Access or ODBC is waiting for a space in some
buffer to open up and eventually decides to remove the oldest 'thing' -
whatever that is.

A search of Google Groups shows that lots of people have had this
problem - is there nobody out there that knows the answer?

cheers

Jeremy

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:14 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com