DBI with SQL Server

E

Eli Tucker

Can someone give me a little help with DBI when connecting to SQL
Server? I've dug around a bit, but can't get a simple select statement
to work. Here's what I'm trying:

require 'dbi'
db = DBI.connect("DBI:ODBC:driver={SQL
Server};Server=kint;Database=MyJournal;UID=test;PWD=test")
sql = "SELECT * from UserInfo"
db.select_all(sql) do |row|
row.each_value do |value|
puts value
end
end
db.disconnect

I get the following error:

c:/tools/ruby/lib/ruby/site_ruby/1.8/DBD/ODBC/ODBC.rb:78:in `connect':
S1090 (0) [Microsoft][ODBC Driver Manager] Invalid string or buffer
length (DBI::DatabaseError)
from c:/tools/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:550:in `connect'
from c:/tools/ruby/lib/ruby/site_ruby/1.8/dbi/dbi.rb:367:in `connect'
from sql.rb:2

I'm using the one-click windows installation (ruby 1.8.1 (2004-01-27)
[i386-mswin32]).

Thanks,
Eli
 
J

Joey Gibson

Eli said:
Can someone give me a little help with DBI when connecting to SQL
Server? I've dug around a bit, but can't get a simple select statement
to work. Here's what I'm trying:

Get the latest rubydbi distribution. Extract the ADO.rb file. Copy it to
X:\Ruby\lib\ruby\site_ruby\1.8\DBD\ADO\ADO.rb Then you can do things
like this:

# Make sure the "dsn =" stuff is all on one line; it may wrap in this email
dsn= 'DBI:ADO:provider=SQLOLEDB;Data Source=localhost;Initial
Catalog=test;User Id=sa;Password=password;'

DBI.connect(dsn) do |conn|
conn.select_all("SELECT * FROM foo") do |row|
puts row[:Id]
end
end

Of course this assumes you are on a Windows box. ADO.rb depends on
Win32OLE, which (I would assume) only works on Windows.





--
She drove a Plymouth Satellite
Faster than the Speed of Light...

http://www.joeygibson.com/blog
http://www.joeygibson.com/blog/life/Wisdom.html
Atlanta Ruby User Group http://www.AtlRUG.org
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top