我正在为按钮夜间部署自动部署数据库脚本。我的第一种方法是在 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)