sqlapi mysql_无法使用SQLAPI ++连接到MYSQL

bd96500e110b49cbb3cd949968f18be7.png

I am new to working on SQLAPI++. I have everything installed, i.e. MYSQL, SQLAPI++ and I am using Code:Block++ as the editor for my C++ program. I was trying to connect to the database that I had created in the MYSQL, but I am unable to. I see the following error when I invoke Connect() written in SQLAPI++

Process returned -1-73741819(0xC0000005) execution time: 0.431s.

The MYSQL is running on my local machine on port no 3306.

int main(int argc, char* argv[])

{

SAConnection con;

SACommand cmd;

int id =0;

string name = "";

cout<

try

{

con.Connect ("sampledb",

"root",

"abcd",

SA_MySQL_Client);

std::cout<

cout<

cmd.setConnection(&con);

cmd.setCommandText("SELECT * FROM sampledb.table1");

cmd.Execute();

while(cmd.FetchNext())

{

id = cmd.Field("id").asLong();

name = cmd.Field("name").asString();

std::cout<

std::cout<

}

con.Commit();

con.Disconnect();

std::cout<

}

catch(SAException &x)

{

try

{

con.Rollback ();

}

catch(SAException &)

{

}

std::cout<

printf("%s\n", (const char*)x.ErrText());

}

return 0;

}

The code compiles successfully. I am running on Windows 10 machine currently. I wonder what could be wrong with the above code. I have a doubt with the way we mention the database address in the Connect function or does it seem to be some other issue?

解决方案

I tried by installing everything again. This time I used CodeBlock 10.0.5, MySQL 5.5 and MySqlConnector C++ 1.1, and it worked without any issues this time around. Probably it was a compatibility issue earlier which was causing the exception. Earlier I had installed the latest version of CodeBlock, i.e. 16 and MySQL 5.7 along with the SQL connector

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值