windows tiny_tds 在第二次执行时失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7901306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
tiny_tds failed at the second execute
提问by ohho
Today, tiny_tds suddenly does not accept more than one execute
and returns:
今天tiny_tds突然不接受多一个execute
,返回:
C:\>ruby test_use.rb
one
two
C:/test_use.rb:15:in `execute': Attempt to initiate a new Adaptive Server operation with results pending (TinyTds::Error)
from C:/test_use.rb:15
The code is simply as three USE
s:
代码很简单,就是三个USE
:
require 'rubygems'
require 'yaml'
require 'fastercsv'
require 'tiny_tds'
require 'iconv'
CONFIG = YAML.load_file("config.yml")
client = TinyTds::Client.new(:username => CONFIG["db"]["username"], :password => CONFIG["db"]["password"],
:host => CONFIG["db"]["server"], :database => CONFIG["db"]["database"])
puts "one"
client.execute("USE DATAFEED")
puts "two"
client.execute("USE DATAFEED")
puts "three"
client.execute("USE DATAFEED")
Any clue what is the problem? I tried rebooting the Windows machine already.
任何线索是什么问题?我已经尝试重新启动 Windows 机器。
采纳答案by Klaus
You have to terminate the execute with a do
:
您必须使用以下命令终止执行do
:
Client.execute("...").do
Client.execute("...").do
回答by jspooner
Here is an example of how I do it.
这是我如何做的一个例子。
results = $regcenter_db.execute("select top 10 * from events")
event_ids = results.collect { |i| i["event_id"] }
results.do
回答by Arnold Roa
You have to call do
OR cancel
. If you are doing something like getting a partial results, and you are not interested in execute the do
method you can call cancel
to abort the query.
您必须致电do
OR cancel
。如果您正在执行诸如获取部分结果之类的操作,并且您对执行do
可以调用cancel
以中止查询的方法不感兴趣。
回答by Aweston
According to the documentation for TinyTdson GitHub:
It is important that you either return the data from the query, most likely with the #each method, or that you cancel the results before asking the client to execute another SQL batch. Failing to do so will yield an error.
重要的是您要么从查询中返回数据,最有可能使用 #each 方法,要么在要求客户端执行另一个 SQL 批处理之前取消结果。不这样做会产生错误。
To cancel the query, use the cancel
method:
要取消查询,请使用以下cancel
方法:
client.execute("USE DATAFEED").cancel