...

View Full Version : problem using TADOConnection in Builder 2007 C++



dsylebee
11-27-2009, 08:28 PM
Hi all I created a small utility class which isn't finished but it's comming soon D:

I need a litle help on something hope you guys can help me.

the problem is that I get an EAccessViolation and I dont know why.
i'll comment where I get the EAccessViolation.


CADOUtil.h


//---------------------------------------------------------------------------

#ifndef ADOUtilH
#define ADOUtilH

#include <string>
#include <ADODB.hpp>
#include <DB.hpp>

class CADOUtil
{
public:
CADOUtil();
CADOUtil(std::string conString);
bool TryConnection();
bool TryConnection(std::string conString);
void SetConnectionString(std::string conString);
int DbQuery(std::string TSQLQuery);
int DbQuery(std::string TSQLQuery, std::string conString);

private:
std::string m_ConnectionString;
TADOConnection *m_Connection;
};
//---------------------------------------------------------------------------
#endif



my .cpp file ( I just put the methodes that are used. )


void CADOUtil::SetConnectionString(string conString)
{
m_ConnectionString = conString;
}

bool CADOUtil::TryConnection()
{
try
{
OutputDebugString( m_ConnectionString.c_str() );
// LINE WITH EROR EAcessViolation
m_Connection->ConnectionString = m_ConnectionString.c_str();
m_Connection->Open();
m_Connection->Close();
return true;
}
catch( ... )
{
OutputDebugString("FAILED TO CONNECT TO DATABASE");
return false;
}
}


Where im calling from a constructor in another class.

Thanks in advance.


string ConString = "Provider=Microsoft.Jet.OLEDB.4.0;";
ConString += "C:\LCS32_BACKOFFICE_PROTOTYPE\Debug\lcsbo_test.mde;";
ConString += "Persist Security Info=False";

CADOUtil AdoUtil(ConString);
AdoUtil.TryConnection();


I have tryed casting also and it dosen't work.
still does not work
m_Connection->ConnectionString = (WideString)m_ConnectionString.c_str();

dsylebee
11-30-2009, 05:55 PM
The answer was

just to add

this->m_Connection = new TADOConnection(NULL);



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum