c 连接mysql 变卡,使用C ++连接器的C ++ 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

here is my code

#include

#include

#include

#include

#include

#include

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

}

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.

Here is the error Exception thrown at 0x000007FEFD39A06D in MysqlConn.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x000000000014F5D0.

Thanks

解决方案

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

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.

The solution is rolling back the CPPCONN_PUBLIC_FUNC= configuration.

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值