Jump to content
  • Advertisement
Sign in to follow this  
da_cobra

ADO database problem

This topic is 4848 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to create an ADO database with my own created class but came upon a problem. I'm just started programming and when I run my application, everything is fine untill I close my application. Then I get a "read or write (written) on the memory failed!" error (trying to translate the error to English) I already did some searching and when I comment this line out my application runs and ends fine : m_piAdoRecordBinding->BindToRecordset(&m_rsADORecSet) ;
HRESULT CAdoDatabase::InitDatabase()
{
	::CoInitialize(NULL) ;

	m_strConnection = _T("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = ..//Database.mdb") ;
	m_strCmdText = _T("select * from personen") ;
	m_pRS = NULL ;
	m_piAdoRecordBinding = NULL ;

	m_pRS.CreateInstance(__uuidof(Recordset)) ;
	
	m_pRS-> Open((LPCTSTR)m_strCmdText,
				(LPCTSTR)m_strConnection,
				adOpenKeyset,
				adLockOptimistic,
				adCmdUnknown) ;
	
	m_pRS-> QueryInterface(__uuidof(IADORecordBinding), (LPVOID*) &m_piAdoRecordBinding) ;

	m_piAdoRecordBinding-> BindToRecordset(&m_rsADORecSet) ;
	
	return S_OK ;
}

HRESULT CAdoDatabase::TerminateDatabase()
{
	if (m_pRS)
		m_pRS-> Close() ;

	if (m_piAdoRecordBinding)
		m_piAdoRecordBinding-> Release() ;

	m_pRS = NULL ;
	
	::CoUninitialize() ;

	return S_OK ;
}


any1 knows what I did wrong? this is code that I got from my teacher and works fine in another application

Share this post


Link to post
Share on other sites
Advertisement
Make sure you get a valid pointer from QueryInterface...try something along these lines...I think if you debugged this, you'd probably see that m_piAdoRecordBinding == NULL because the query interface failed...I could be wrong...


//.... other stuff ....


// there is also a FAILED macro you could use in place of SUCCEEDED
if(SUCCEEDED(m_pRS-> QueryInterface(__uuidof(IADORecordBinding), (LPVOID*) &m_piAdoRecordBinding) ) )
m_piAdoRecordBinding-> BindToRecordset(&m_rsADORecSet) ;
else
return(E_FAIL);

return S_OK ;





hth...
[EDIT] SUCCEEDED or FAILED macro work on any function that returns a HRESULT [/EDIT]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!