Search code examples
c++mysqlvisual-studiomysql-connectorconnector

Visual Studio 2019 error on build C++ MySQL connector


I downloaded libraries and headers from Connector/C++ 8.0.26 and tried all of them one by one, But always get error on building point.

I used Visual Studio 2019 (Version 16.10.0) and created a simple console app based on example from MySQL website. The original example is like this:

#include "mysql_connection.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>

using namespace std;

int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' »
   AS _message'..." << endl;

try {
  sql::Driver *driver;
  sql::Connection *con;
  sql::Statement *stmt;
  sql::ResultSet *res;

  /* Create a connection */
  driver = get_driver_instance();
  con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
  /* Connect to the MySQL test database */
  con->setSchema("test");

  stmt = con->createStatement();
  res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
  while (res->next()) {
    cout << "\t... MySQL replies: ";
    /* Access column data by alias or column name */
    cout << res->getString("_message") << endl;
    cout << "\t... MySQL says it again: ";
    /* Access column data by numeric offset, 1 is the first column */
    cout << res->getString(1) << endl;
  }
  delete res;
  delete stmt;
  delete con;

} catch (sql::SQLException &e) {
  cout << "# ERR: SQLException in " << __FILE__;
  cout << "(" << __FUNCTION__ << ") on line " »
     << __LINE__ << endl;
  cout << "# ERR: " << e.what();
  cout << " (MySQL error code: " << e.getErrorCode();
  cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}

cout << endl;

return EXIT_SUCCESS;
}

I got same error with different configuration (32,64,Debug|release ....):

error on build

I read more than +100 topics here, also in other sites about same problem as well and try every solution that they provided but none of them work.

The only solution I not checked yet is to download the VS 2015 and try with that.

Now we are in 2021, is this really the right solution to create a C++/MySQL simple APP or I have to do something else?


Solution

  • After checking all solution around the internet finally the problem solved by copying all .dll files to the c:/windows !