tiny_tds 在第二次执行时失败

发布于 2024-12-11 20:34:05 字数 811 浏览 0 评论 0原文

今天,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

代码很简单,只有三个 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")

有什么线索吗?我已经尝试重新启动 Windows 机器。

Today, tiny_tds suddenly does not accept more than one execute and returns:

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 USEs:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

以歌曲疗慰 2024-12-18 20:34:05

这是我如何做的一个例子。

results = $regcenter_db.execute("select top 10 * from events")
event_ids = results.collect { |i| i["event_id"] }
results.do    

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    
2024-12-18 20:34:05

您必须使用 do 终止执行:

Client.execute("...").do

You have to terminate the execute with a do:

Client.execute("...").do

岁月静好 2024-12-18 20:34:05

根据 GitHub 上的 TinyTds 文档

重要的是,您要么从查询,最有可能使用 #each 方法,或者在要求客户端执行另一个 SQL 批处理之前取消结果。如果不这样做将会产生错误。

要取消查询,请使用 cancel 方法:

client.execute("USE DATAFEED").cancel

According to the documentation for TinyTds on 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.

To cancel the query, use the cancel method:

client.execute("USE DATAFEED").cancel
谁许谁一生繁华 2024-12-18 20:34:05

您必须调用docancel。如果您正在执行诸如获取部分结果之类的操作,并且您对执行 do 方法不感兴趣,则可以调用 cancel 来中止查询。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文