List:MySQL++« Previous MessageNext Message »
From:B Singh Date:October 14 2009 4:48am
Subject:Connection Object throws exception
View as plain text  
Hi All,

I always get exception when tryign to delete "m_pcommonMasterDBCon" object
in following code.   Is it bad idea to have connection object in heap ? I
see all samples are  using stack variable for connection and only heap for
multistatementoption.


DBManager::CheckConnection() {

if(m_pcommonMasterDBCon && (m_pcommonMasterDBCon->ping()== false))
{
//m_pcommonMasterDBCon->disconnect();  // have seen exception
m_bDBConnection = false;
if(m_pcommonMultiStOption)
    delete m_pcommonMultiStOption;
//if(m_pcommonMasterDBCon)
       //delete m_pcommonMasterDBCon;  * // Always throws exception *


m_pcommonMasterDBCon = new mysqlpp::Connection(false);
m_pcommonMultiStOption = new mysqlpp::MultiStatementsOption(true);
m_pcommonMasterDBCon->set_option(m_pcommonMultiStOption);
if(m_pcommonMasterDBCon->connect(m_DBName.c_str(),
m_MasterDBServerName.c_str(),
    m_DBUser.c_str(), m_DBPassword.c_str(), m_DBPort) == true)
        .....

}

DBManager::~DBManager()
{
if(m_pcommonMultiStOption)
{
   delete m_pcommonMultiStOption;
}

if(m_pcommonMasterDBCon)
{
   m_pcommonMasterDBCon->disconnect();
   delete m_pcommonMasterDBCon;  *// crashes always *
}

}


Thanks

Thread
Connection Object throws exceptionB Singh14 Oct
  • Re: Connection Object throws exceptionWarren Young14 Oct