Crashes when running MySQL Connector/C++ from Visual Studio


I'm having a bit of issues with trying to run a compiled program that uses the MySQL connector, in C++. It compiles just fine, but when running it, it'll crash immediately - seemingly so on the line that's meant to connect. I've set up all additional libraries, dependencies, pre-processors and linker inputs, and I'm using the Release solution configuration. I am running Microsoft Visual Studio 2012.

The error I'm getting is the following: Unhandled exception at 0x6E69AF48 (msvcr90.dll) in MyLittleSQL.exe: 0xC0000005: Access violation reading location 0x00000024.

And the call stack:

MyLittleSQL.exe!main() Line 24 C++
MyLittleSQL.exe!__tmainCRTStartup() Line 536 C

Line 24 is:

con = driver->connect("tcp://", "sepples_su", "easy");

And the full source code is:

#include <stdlib.h>
#include <iostream>

#include "mysql_connection.h"
#include "mysql_driver.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;

int main(void)
        sql::Driver *driver;
        sql::Connection *con;
        sql::Statement *stmt;
        sql::ResultSet *res;

        /* Create a connection */
        driver = get_driver_instance();
        con = driver->connect("tcp://", "sepples_su", "easy");

        /* Connect to the MySQL test database */

        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 fata 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;

This is actually one of the examples taking from the Connector documentation, but I wanted to make sure it wasn't my own fault first.

Any help here would be appreciated, thank you.

asked on Stack Overflow Nov 29, 2012 by mtaanquist

2 Answers


With help from @LyubomirVasilev I compiled the C++ Connector on my own with settings for Visual Studio 11 (2012). Replacing the other lib and dll files with the compiled here, it worked perfectly after.

Information on doing this can be found here for any others:

answered on Stack Overflow Nov 29, 2012 by mtaanquist • edited Nov 12, 2015 by cp.engr

The latest C++ MySQL connector is compiled with VC9 runtime libraries (Visual studio 2008). Visual studio 2012 uses VC11 libraries so it's obvious why your program crashed. Your program must use the same runtime libraries as MySQL C++ connector:

Unhandled exception at 0x6E69AF48 (msvcr90.dll) <--- VC9

You must compile your program with Visual studio 2008 which uses VC9 libraries or compile MySQL C++ connector from source with Visual studio 2012.

answered on Stack Overflow Sep 20, 2015 by BJovke

User contributions licensed under CC BY-SA 3.0