加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

使用TinyTds Ruby Gem解析并运行.sql脚本

发布时间:2020-12-17 02:02:13 所属栏目:百科 来源:网络整理
导读:我正在为按钮夜间部署自动部署数据库脚本.我的第一种方法是在 Windows终端上使用sqlcmd,将结果保存到txt文件,并解析它以确保脚本成功.解析文件并找到返回代码是有问题的,所以我转向TinyTds.这是我的代码: client = TinyTds::Client.new(:username = DB_USER
我正在为按钮夜间部署自动部署数据库脚本.我的第一种方法是在 Windows终端上使用sqlcmd,将结果保存到txt文件,并解析它以确保脚本成功.解析文件并找到返回代码是有问题的,所以我转向TinyTds.这是我的代码:

client = TinyTds::Client.new(:username => DB_USER,:password => DB_PASSWORD,:dataserver => DB_SERVERNAME,:timeout => 1200)
      result = client.execute(IO.read(filename))
      puts result.return_code

产生nil或以下错误(取决于.sql脚本的内容)

run_sql.rb:24:in `execute': Attempt to initiate a new Adaptive Server operation with results pending (TinyTds::Error)

更改

result = client.execute(IO.read(filename))

result = client.execute(IO.read(filename)).do

产量

run_sql.rb:26:in `do': Incorrect syntax near 'go'. (TinyTds::Error)

解决方法

我认为您的答案将依赖于您尝试提供给TinyTDS的SQL.也许批处理的格式不正确.你也可能只想做result = client.execute(data).也就是这样.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读