C++ MySQL Connector Unable to Disconnect TCP Connection on sql::Connection close() call -
i having difficulties terminating mysql connection created using mysql c++ connector 1.1.3
sql::connection *con; /* creating connection */ //.... /* executing statements */ //.. con->close(); // should terminate tcp connection
but after calling close() function tcp connection mysql server doesn't terminate. disconnects after application process terminated.
after close found following:
1>
//checkedclosed() function of mysql_connection class if (!intern->is_valid) { // returns true throw sql::sqlexception("connection has been closed");
2>
mysql_connection::clearwarnings() { cpp_enter_wl(intern->logger, "mysql_connection::clearwarnings"); // intern closed = false intern->warnings.reset(); }
please guide me how can terminate mysql connection.
update:
class mysqlconn { private: sql::driver *driver; sql::connection *con; public: bool initdbconnection(); bool closedbconnection(); }; bool mysqlconn::initdbconnection() { this->driver = get_driver_instance(); try { this->con = this->driver->connect(host, user, pass); this->con->setschema(db); return true; } catch(sql::sqlexception &e) { clogger::logevent("failed connect database server" ,e.what()); return false; } } bool mysqlconn::closedbconnection() { try { this->conn->close(); return true; } catch(sql::sqlexception &e) { clogger::logevent("failed close connection database server" ,e.what()); return false; } } void someclass::somefunc() { mysqlconn db_conn; if(db_conn.initdbconnection()) { //do somthing db_conn.closedbconnection(); } }
so, suppose don't have call destructor in case once scope of someclass::somefunc() ends object gets destructed?
solved:
it simple solution in end.
bool mysqlconn::closedbconnection() { try { this->con->close(); delete this->con; this->driver->threadend(); return true; } catch(sql::sqlexception &e) { clogger::logevent("failed close connection database server" ,e.what()); return false; } }
now connection goes time_wait established , means connection has been terminated end , waiting corrupted frame resend other end. , after wait time on tcp connection terminated.
regards
gencoide_hoax
Comments
Post a Comment