# Ruby ODBC SQL Server Errors

**URL:** <https://www.ruby-forum.com/t/ruby-odbc-sql-server-errors/74423>\
**Category:** Ruby\
**Created:** [November 6, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/ruby-odbc-sql-server-errors/74423 "2006-11-06T19:50:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 6, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/ruby-odbc-sql-server-errors/74423/1 "2006-11-06T19:50:20Z")

</div>

I have a ruby script that inserts data into a SQL Server Express  
database. The inserts work but I keep getting errors like the following  
“WARNING: STMT 0x2954f50 was not dropped before garbage collection.”

# Here’s the script

require ‘odbc’

c=ODBC::connect(‘SMD’)  
t1 = Time.now

aFile = File.open(“C://temp/DMERECAP.SDF”)

aFile.each\_line do |line|  
if $. \< 11  
q =c.prepare(“Insert into  
DMERECAP(recptlo,datepaid,invoicenum,dolapplied,payername,hcpc,servdatepd,patnum)  
values (’#{line[0…6].squeeze(” “)}’ ,’#{line[7…16].squeeze(” “)}’,  
'#{line[17…28].squeeze(” “)}’, '#{line[29…40].squeeze(” “)}’,  
'#{line[48…87].squeeze(” “)}’, '#{line[88…92].squeeze(” “)}’,  
'#{line[145…154].squeeze(” “)}’, '#{line[138…145].squeeze(”  
“).to\_i}’)”)  
q.execute()

```
 end

```

end

puts “Import complete.”  
puts Time.now-t1

if c  
c.disconnect  
end

============

Any help would be appreciated.

thanks,

Luis

---

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 7, 2006, 11:07am UTC](https://www.ruby-forum.com/t/ruby-odbc-sql-server-errors/74423/2 "2006-11-07T11:07:53Z")

</div>

Hi Luis,

I asked Christian Werner about this in the past. He told me that these  
are internal warnings intended to remind the lazy programmer to  
close/drop his ODBC statements. If you don’t do so, their cleanup  
doesn’t occur until garbage collection. Christian said these warnings  
are “…not a bug but a feature.”

Try q.drop after q.execute and see if that fixes things for you…

Ben

---

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 7, 2006, 11:07am UTC](https://www.ruby-forum.com/t/ruby-odbc-sql-server-errors/74423/3 "2006-11-07T11:07:55Z")

</div>

Thanks,

That did the trick.

Luis
