From: Peter Fitzgibbons Date: 2005-11-05T02:43:47+09:00 Subject: Re: MS SQL Access from Ruby in Windows ------=_Part_30841_20502462.1131126224679 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 11/4/05, Sean O'Halpin wrote: > > On 11/4/05, Horacio Sanson wrote: > > > > Can someone point me where to learn how to access a MS SQL 2000 databas= e > > 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 =3D 'ODBC' > server =3D "SQLSERVER_NAME" > # or this if you want to access an instance > #server =3D "SQLSERVER_NAME\\INSTANCE_NAME" > database =3D 'Database' > user =3D 'user' > password =3D 'password' > > connection_string =3D "DBI:ODBC:Driver=3D{SQL > Server};Server=3D#{server};Database=3D#{database};Uid=3D#{user};Pwd=3D#{p= assword}" > > begin > # connect > db =3D DBI.connect(connection_string, user, password) > # get data and print > row =3D db.select_one("SELECT XETDATE()") > puts "result: " + row[0].to_s > rescue DBI::DatabaseError =3D> e > puts "Error #{e.errstr}" > ensure > # disconnect from server > db.disconnect if db > end > > Regards, > > Sean > > Unless you LOVE writing Klocs... use Rails. The framework saves a boatloa= d of keystrokes. -- Peter Fitzgibbons ------=_Part_30841_20502462.1131126224679--