使用C ++连接器的C ++ MySQL连接bad_alloc [英] c++ mysql connection bad_alloc using c++ connector

查看:487
本文介绍了使用C ++连接器的C ++ MySQL连接bad_alloc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图建立一个简单的mysql连接,但是得到一个bad_alloc,即使看类似的文章,我也想不出解决方法

Trying to build a simple mysql connection, but getting a bad_alloc and I can't figure out how to solve this, even looking at similar posts

这是我的代码

#include <iostream>
#include <stdlib.h>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>

#include "mysql_connection.h"
#include "cppconn\driver.h"
#include "cppconn\statement.h"
#include "cppconn\connection.h"
#include "cppconn\exception.h"
#include "cppconn\prepared_statement.h"
#include "cppconn\statement.h"


using namespace std;
using namespace sql;

int main()
{

    Driver *driver;
    Connection *conn;
    Statement *stmt;

    driver = get_driver_instance();
    conn = driver->connect("127.0.0.1:3306", "root", "root"); // breaks here
    stmt = conn->createStatement();
    stmt->execute("USE mydb");

    return 0;
}

我正在使用mysql-connector-c++-1.1.7 mysqlcppconn.lib用作依赖项 mysqlcppconn.dll.exe位于同一目录.

I'm using mysql-connector-c++-1.1.7 mysqlcppconn.lib is used as a dependencies mysqlcppconn.dll is located in the same dir as the .exe is.

这是错误Exception thrown at 0x000007FEFD39A06D in MysqlConn.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000000014F5D0.

谢谢

推荐答案

我也遇到了此错误.就我而言,我正在Windows中使用VS2015进行编译.

I also had this error. In my case I am compiling using VS2015 in Windows.

我第一次选择编译静态版本的MySQL库.然后,我决定编译动态版本.这次,内存中的错误bad_alloc消失了.

First time I choose compile static version of the MySQL lib. Then later I decided to compile the dynamic version. This time the error bad_alloc at memory went off.

该解决方案正在回滚CPPCONN_PUBLIC_FUNC =配置.

The solution is rolling back the CPPCONN_PUBLIC_FUNC= configuration.

转到C ++>预处理程序>预处理程序定义下的项目属性页,然后删除项目CPPCONN_PUBLIC_FUNC=".

Go to project Property Pages, under C++ > Preprocessor > Preprocessor Definitions and remove the item CPPCONN_PUBLIC_FUNC=".

这篇关于使用C ++连接器的C ++ MySQL连接bad_alloc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆