Matlab - [Microsoft] [ODBC SQL Server驱动程序]连接忙于另一个hstmt的结果

时间:2018-01-11 11:28:17

标签: sql-server database matlab odbc

我正在运行Matlab的几个SQL脚本。在过去的几个月里,没有任何问题。但是,从本周开始,我开始收到以下错误:

  

使用database.jdbc.connection / exec时出错(第53行)[Microsoft] [ODBC   SQL Server驱动程序]连接忙于另一个hstmt的结果

我已经在Matlab上正确安装了我的ODBC驱动程序,并按如下方式运行SQL查询:

%  connect
conn = database('connectionName','user','password');

% I actually alter between two queries, but put the same here as an example
for i=1:2

   querynew  = "SELECT * FROM tbl";   

   results   = exec(conn, querynew); % the error is triggered here
   results   = fetch(results);
   Data      = results.Data;

end

close(conn)

1 个答案:

答案 0 :(得分:1)

尝试使用close(results)

关闭光标
for i=1:2

   querynew  = "SELECT * FROM tbl";   

   results   = exec(conn, querynew); % the error is triggered here
   results   = fetch(results);
   Data      = results.Data;
   close(results);

end

https://ch.mathworks.com/help/database/ug/close.html?requestedDomain=true