MySQL Forums
Forum List  »  Connector/C++

Cannot connect to a MySQL database from a C++ program with MySQL Connector/C++: exception thrown
Posted by: Pietro Mele
Date: February 06, 2013 04:35AM

I have a connection problem to a MySQL database from a C++ program:

std::string server, user, password;
SetParams(server, user, password);
boost::shared_ptr<sql::Connection> conn;
sql::Driver *driver = get_driver_instance();

if(driver == 0) { /* error; never reached */ }

try {
conn.reset(driver->connect(server, user, password));

assert(conn != 0);

if(!conn->isClosed()) // <-- exception thrown
{
// Connection established
}
else {
// Connection failed
}
}
catch (sql::SQLException &e)
{
cerr << e.what << e.getErrorCode() << e.getSQLState() << endl;
}
The sql::Connection::isClosed() function throws this exception:

SQLException: Connection has been closed
MySQL error code: 0
SQLState: HY000
The values for server, user and password are correct (they work connecting from MySQL-Workbench), the DB is up and running.

I do not know where else to look...
Thank you.

Platform:
Linux - OpenSuse 11.4
MySQL 5.x
MySQL Connector/C++ 1.0.5

*** UPDATE ***

The code as shown here works correctly. The problem must be somewhere else in the program...



Edited 1 time(s). Last edit at 02/06/2013 10:57AM by Pietro Mele.

Options: ReplyQuote


Subject
Views
Written By
Posted
Cannot connect to a MySQL database from a C++ program with MySQL Connector/C++: exception thrown
4520
February 06, 2013 04:35AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.