error:2014 Commands out of sync; you can't run this command now
如下错误:

分析原因: 前端ajax请求后台,共用同一个链接。
搜索别人的解决方案:http://blog.csdn.net/grass_ring/article/details/3499402
用mysql C API 调用存储过程,并返回结果集。需要注意几个问题:
在建立链接的时候要加选项CLIENT_MULTI_STATEMENTS 或 CLIENT_MULTI_RESULTS,以便可以让query执行多个语句。
mysql_real_connect(mySQL,serverIP,user,password,database,serverPort,NULL,CLIENT_MULTI_STATEMENTS)
当query时可能产生错误error: Commands out of sync; you can't run this command now Mysql文档中说明错误:Commands out of sync
If you get Commands out of sync; you can't run this command now in your client code, you are calling client functions in the wrong order.
This can happen, for example, if you are using mysql_use_result() and try to execute a new query before you have called mysql_free_result(). It can also happen if you try to execute two queries that return data without calling mysql_use_result() or mysql_store_result() in between. 当执行完query后,mysql将结果集放在一个result集中,产生以上问题的原因有两个:
一是未将MYSQL_RES所指对象释放,即在下次查询时要mysql_free_result();
二是结果result集不为空,这个原因比较隐蔽。解决方法可以用如下写法:
do
{
/* Process all results */
printf("total affected rows: %lld", mysql_affected_rows(mysql));
...
if (!(result= mysql_store_result(mysql)))
{
printf(stderr, "Got fatal error processing query/n");
exit();
}
process_result_set(result); /* client function */
mysql_free_result(result);
} while (!mysql_next_result(mysql));
还有个问题感觉比较奇怪,我调用一个存储过程,存储过程中就一句select
Create procedure test()
Begin
Select * from test ;
End ;
用以上方法处理结果集循环会执行两次,开始我只调了一次result= mysql_store_result(mysql)),导致以后执行query报2014错误。
最终,我为每个请求,建立一个connection,并且在使用完毕后,就主动释放。
error:2014 Commands out of sync; you can't run this command now的更多相关文章
- 使用otl,报错:mysql Commands out of sync; you can't run this command now
1.代码如下: void TestCache(otl_connect& otlConn) { try { ] = {}; sprintf(sql,"call test1(1)&quo ...
- python mysql 2014 Commands out of sync; you can't run this command now
这个问题出现再 mysql和c 的api. 简单的解决方法是不使用api直接把整个连接和命令传过去. 例如,cmd = 'mysql -h 192.168.32.210 -P 3316 -u bfd ...
- _mysql_exceptions.ProgrammingError:(2014, "commands out of sync; you can't run this command now")
今天,测试dashboard上的一些graph, 发现,当多个graph同时向后台请求数据(异步)的时候, 出现了上述错误.而且,三个bug交替出现,另外两个bug分别是:python stop re ...
- mysql_query error:Commands out of sync;you can't run this command now
MYSQL_REST *result没有释放, 用mysql_free_result(result)即可.
- C mysql (C API Commands out of sync; you can't run this command now)
错误出现在当一个用户使用查询,另一个用户再使用此sql连接进行查询的时候: 原因是因为上一次使用此sql连接进行查询时没有将所有的结果集给释放掉,在所有使用此sql连接进行查询的地方将所有的结果集给释 ...
- Xcode10适配——Error:Multiple commands produce
今天苹果正式推送了iOS12,今天上午就更新了最新的iOS,及Xcode10.这次更新还行,不需要我们对以前的项目紧急修复,大动手术. 用Xcode10跑之前的项目,也就报了一种类型的错误:Multi ...
- MySql: ”Commands out of sync“Error (Connect/C++)
使用 Connector/C++ 查询 Mysql , 连续调用存储过程时 会出现如下: Commands out of sync; you can't run this command now,st ...
- GitHub 上下载代码运行报错 :'The sandbox is not sync with the Podfile.lock\'
问题描述: github下载的Demo,很多时候使用到CocoaPods,有的时候因为依赖关系或者版本问题不能编译运行.出现例如The sandbox is not sync with the Pod ...
- 【故障•监听】TNS-12518、TNS-00517和 Linux Error:32:Broken pipe
[故障|监听]TNS-12518.TNS-00517和 Linux Error:32:Broken pipe 1.1 BLOG文档结构图 1.2 前言部分 1.2.1 导读和注意事项 各位技术爱 ...
随机推荐
- JVM ,Java paper
http://files.cnblogs.com/files/WCFGROUP/IntroductiontoCompilerConstructioninaJavaWorld.pdf A Fast Wr ...
- Install haroopad on centos7
1.Install libs sudo yum install systemd-libs -y 2.Download haroopad goto haroopad1 download bin pack ...
- Maven工程pom.xml文件秒变gradle工程的命令
下面是一个maven工程,我想把它转成gradle项目,怎么办? 打开cmd命令行窗口,切换到你的maven工程的pom.xml文件所在目录,然后执行如下命令: gradle init --type ...
- securecrt5序列号
securecrt5序列号 Name: Apollo InteractiveCompany: Apollo InteractiveSerial Number: 03-50-02 ...
- 【转】Hive优化总结
优化时,把hive sql当做map reduce程序来读,会有意想不到的惊喜. 理解Hadoop的核心能力,是hive优化的根本.这是这一年来,项目组所有成员宝贵的经验总结. 长期观察hadoo ...
- ajax 和xmlHttpRequest区别
什么是 ajax ajax 即“Asynchronous JavaScript and XML”(异步 JavaScript 和 XML),也就是无刷新数据读取. http 请求 首先需要了解 htt ...
- USB 驱动之 usb_register 函数解析
前段时间在kernel 添加了 USB to LAN 模块 AX88772B 的驱动. 根据相关添加解析一下 usb_register_driver 函数 drivers/net/usb/asix.c ...
- [3G/4G]3G/4G模块开发
转自:http://mywutuobang.blog.sohu.com/260073467.html 一. 修改内核支持3G模块,一般内核需要枚举相关的通讯模块,其接口为串口,其数据接口和通讯接口枚举 ...
- Python idle安装与使用教程 调试、下载
Python idle安装与使用教程 调试.下载 今天我们就来讲一下如何安装Python idle编辑器,也它的调试和使用. 第一步,我们先去下载一个Python idle程序安装包. 本节讲的是wi ...
- Ubuntu14.04使用DEB安装Mysql5.7
下载deb-bundle包 1.mysql下载页面 2.解压 安装(注意安装顺序) 安装顺序如下: 1.mysql-common_5.7.10-1ubuntu14 ...