I am automating the deployment of db scripts for a push button nightly deploy. My first approach was to use sqlcmd on windows terminal, save the results to txt file, and parse it to ensure the script was successful. Parsing the file and finding the return code was problematic, so I turned to TinyTds. Here is my code:
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
Yields either nil or the following error (depending on the contents of the .sql script)
run_sql.rb:24:in `execute': Attempt to initiate a new Adaptive Server operation with results pending (TinyTds::Error)
Changing
result = client.execute(IO.read(filename))
to
result = client.execute(IO.read(filename)).do
yields
run_sql.rb:26:in `do': Incorrect syntax near 'go'. (TinyTds::Error)
I think your answer would rely in the SQL you are trying to feed to TinyTDS. Perhaps the batch is not formatted properly for it. You also may want to just do
result = client.execute(data).eachtoo.