简体   繁体   中英

Can't get MySQL Connector/C++ to work - Unhandled exception (sql::SQLException) Visual Studio 2010

So I have been trying to get a basic connection to a MySQL database for a few days now, and I have tried every which way there seems to be to get the MySQL Connector/C++ to work. Here is my code so far:

#include <iostream>
#include <mysql_driver.h>

int main(){
    sql::mysql::MySQL_Driver *driver;
    sql::Connection *con;

    driver = sql::mysql::get_mysql_driver_instance();
    con = driver->connect("http://localhost/", "root", "");

    delete con;

    return 0;
}

I am using MSVS2010, MySQL Connector/C++ 1.1.6, Boost 1.5.9 I have the correct includes, and libraries along with the linker set up for the connector. I have also included boost 1.5.9.

When I compile and execute, I get the same error every time:

Unhandled exception at 0x75d9c42d in MySQL Test.exe: Microsoft C++
exception: sql::SQLException at memory location 0x0041f140..

Here is the Call Stack:

>   MySQL Test.exe!__tmainCRTStartup()  Line 555 + 0x17 bytes   

And here is the relevant code:

550    #ifdef WPRFLAG
551        __winitenv = envp;
552        mainret = wmain(argc, argv, envp);
553    #else  /* WPRFLAG */
554        __initenv = envp;
555        mainret = main(argc, argv, envp);
556    #endif  /* WPRFLAG */

I have tried reinstalling the MySQL server and it's components, as well as the connector itself, and I have the correct .dll in the same directory as the Release.

I am trying to connect to a WAMP server, but I don't think it's particularly relevant to the error.

I also tried different versions of MSVS, including 2008 and 2013. I have no idea what the problem is, and there doesn't seem to be any solutions to this issue anywhere online.

I would like to try using CMake to build MySQL Connector/C++ from the source code myself, however I have no idea where to begin, and I don't to want to spend more time aimlessly going in the wrong direction.

Any help would be greatly appreciated as I have spent a lot of time trying to figure this out.

最后,我设法使其正常运行,但是不能与MySQL Connector / C ++一起使用,我必须使用MySQL Connector / C,它可以首次使用,完全没有问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM