0

When querying MSSQL 2008 database using freetds and tinytds gem with syntax below:

db = TinyTds::Client.new(:username => ...)
select = db.execute("EXEC dbo.__stored_procedure__")
db.close

Then this line is causing ruby to crash on windows:

select.each {|x| p x}

Strange thing, when querying simple select:

select = db.execute("SELECT field FROM table")

select.each doesn't crash - it doesn't do any loop either

It doesn't crash webrick nor rails console either.

But when I change code to:

db = TinyTds::Client.new(:username => ...)
select = []
db.execute("EXEC dbo.__stored_procedure__").each { |x|
  select << x
}
db.close

Then it works like a charm (even with select).

Don't how it works on os better than windows...

igy
  • 1
  • 1

1 Answers1

0

Your expectations are incorrect. I suggest you read over the TinyTDS usage here. https://github.com/rails-sqlserver/tiny_tds#tinytdsclient-usage

MetaSkills
  • 1,954
  • 18
  • 15
  • My point was that TDS can easily crash ruby. Just do something with result after closing connection. You wont't get any error - it's lack of simple connection check. I have to do it myself. – igy Oct 01 '12 at 10:59