title: Cannot connect to a MySQL database from a C++ program with MySQL Connector/C++: exception thrown
body: <p>I have a connection problem to a MySQL database from a C++ program:  </p>
  
  <pre><code>std::string server, user, password;
  SetParams(server, user, password);
  boost::shared_ptr&lt;sql::Connection&gt; conn;
  sql::Driver *driver = get_driver_instance();
  
  if(driver == 0) { /* error; never reached */ }
  
  try {
      conn.reset(driver-&gt;connect(server, user, password));
  
      assert(conn != 0);
  
      if(!conn-&gt;isClosed())    // &lt;-- exception thrown
      {
          // Connection established
      }
      else {
          // Connection failed
      }
  }
  catch (sql::SQLException &amp;e)
  {
      cerr &lt;&lt; e.what &lt;&lt; e.getErrorCode() &lt;&lt; e.getSQLState() &lt;&lt; endl;
  }
  </code></pre>
  
  <p>The <code>sql::Connection::isClosed()</code> function throws this exception:  </p>
  
  <pre><code>SQLException: Connection has been closed  
  MySQL error code: 0  
  SQLState: HY000
  </code></pre>
  
  <p>The values for server, user and password are correct (they work connecting from MySQL-Workbench), the DB is up and running.  </p>
  
  <p>I do not know where else to look...<br>
  Thank you.</p>
  
  <p>Platform:<br>
  Linux - OpenSuse 11.4<br>
  MySQL 5.x<br>
  MySQL Connector/C++ 1.0.5  </p>
  
  <hr>
  
  <p>Update:<br>
  Since I read somewhere about possible conflicts between MySQL Connector/C++ and Boost, I tried to use a plain pointer instead of a boost::shared_ptr. Nothing changed.</p>
  
  <hr>
  
  <p>Update 2:<br>
  Isolating this code out of the main program, the connection is done successfully.<br>
  I must look at the bigger picture...</p>