From: Sean O'Halpin Date: 2005-11-05T02:03:21+09:00 Subject: Re: MS SQL Access from Ruby in Windows On 11/4/05, Horacio Sanson wrote: > > Can someone point me where to learn how to access a MS SQL 2000 database > server from within ruby in a Windows machine?? > I use DSN-less connections with the DBI ODBC driver using the One-Click installer out of the box like this: require 'dbi' driver = 'ODBC' server = "SQLSERVER_NAME" # or this if you want to access an instance #server = "SQLSERVER_NAME\\INSTANCE_NAME" database = 'Database' user = 'user' password = 'password' connection_string = "DBI:ODBC:Driver={SQL Server};Server=#{server};Database=#{database};Uid=#{user};Pwd=#{password}" begin # connect db = DBI.connect(connection_string, user, password) # get data and print row = db.select_one("SELECT XETDATE()") puts "result: " + row[0].to_s rescue DBI::DatabaseError => e puts "Error #{e.errstr}" ensure # disconnect from server db.disconnect if db end Regards, Sean