-1

I wrote a program in C++ that connects to MySQL via mysqlcppconn 6.1 in a database running on xampp (I'm using windows). It occurs that, when trying to connect to MySQL the program crashes with no error message and is closed by Windows, leaving me without clues of what happened.

# Line that generates the error:
con = driver->connect("tcp://localhost:3306", "root", "root");

I read that this was and old bug on MySQL connector with C++ but didn't find any viable solutions (other than recompiling this or that).

What could be a solution or workaround for this error?

The application code: https://dl.dropboxusercontent.com/u/85576999/DB8/dbWriteWin.h

1 Answers1

0

From the code shared,

   sql::Driver *driver;
   //driver = get_driver_instance();   it is commented out ?????
   try {
        con = driver->connect("tcp://localhost:3306", "root", "root");
    } catch (SQLException e){
        ev << e.what() << "\n";
    }

The *driver is not initialized and it is used to call the method connect.

Balu
  • 2,247
  • 1
  • 18
  • 23
  • The driver initialization is commented out because it runs into another error (undefined reference to get_driver_instance). – Luis Henrique Sep 25 '15 at 12:45
  • Since ***driver** is not initialized it will point to anywhere and the **connect** method might access the **this** pointer and behaviour is undefined it might crash or it might run some junk code – Balu Sep 25 '15 at 12:48
  • http://stackoverflow.com/questions/5360501/c-function-called-without-object-initialization give more info about using uninitilized pointer objects – Balu Sep 25 '15 at 12:55