c++ - 从 Visual Studio 运行 MySQL Connector/C++ 时崩溃

标签 c++ mysql crash visual-studio-2012 connector

尝试在 C++ 中运行使用 MySQL 连接器的已编译程序时,我遇到了一些问题。它编译得很好,但是当运行它时,它会立即崩溃 - 似乎在连接的线上。我已经设置了所有额外的库、依赖项、预处理器和链接器输入,并且我正在使用 Release 解决方案配置。我正在运行 Microsoft Visual Studio 2012。

我得到的错误如下: MyLittleSQL.exe 中 0x6E69AF48 (msvcr90.dll) 处的未处理异常:0xC0000005:访问冲突读取位置 0x00000024。

调用栈:

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

第 24 行是:

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

完整的源代码是:

#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)
{
    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", "sepples_su", "easy");

        /* 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 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;
}

这实际上是取自连接器文档的示例之一,但我想首先确定这不是我自己的错。

如有任何帮助,我们将不胜感激,谢谢。

最佳答案

在@LyubomirVasilev 的帮助下,我使用 Visual Studio 11 (2012) 的设置自行编译了 C++ 连接器。用这里编译的替换其他lib和dll文件,完美运行。

有关执行此操作的信息可在此处找到其他任何信息:http://dev.mysql.com/doc/refman/5.1/en/connector-cpp-info.html

关于c++ - 从 Visual Studio 运行 MySQL Connector/C++ 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13620963/

相关文章:

php - 包含的 php 文件上的 Session_start 与主页上的 session_start 冲突

c++ - 取消引用已删除的指针总是会导致访问冲突?

ios - 如何复制 ios 版本的 iPhone?

c++ - 如何调用模板类型的正确构造函数?

c++ - 为函数内部的结构分配和初始化值

c++ - 使用 C++ 元编程构建静态字符串

mysql - CentOS 内存使用情况。已使用约 22GB RAM(22GB 可用内存)

mysql - 在遍历结果集时将数据插入 MySQL

c++ - OpenCV Clang mat.hpp 错误 : call to member function 'ptr' is ambiguous

android - 如何获取 Android 崩溃日志?