views:

734

answers:

4

I'm making a simple script using ruby on a Windows 2003 Server. My questions are:

  • How can I connect to a database through ODBC? I will be connecting to both Sybase on Solaris and MSSQL Server.
  • How can I send emails through an Exchange Server 2003?


Update

  • What's the best simple IDE for Ruby scripting? I currently use SciTE (which comes with Ruby)
+2  A: 

There is an ODBC package for the Ruby DBI module available, or you can try to use the ODBC binding for Ruby, which also includes a Win32 binary.

Here an example that uses RDI (stolen from here):

require 'DBI'

# make an ODBC connection
conn = DBI.connect('DBI:ODBC:datasource','your_username','your_password')

# returns a list of the table names from your database
conn.tables

# returns an array with the resultset from your query
rs = conn.select_all('SELECT * FROM TheTable')

(ODBC datasources can be defined using the ODBC Administrator available via Control Panel/Administrative Tools.)

For e-mailing I would suggest you simply use the standard mailing capabilities of Ruby and connect to your Exchange Server through SMTP.

I cannot recommend you a Ruby IDE, though, as I do my text-editing with VIM. :-) Other people might be able to give you a hint on that.

Tomalak
+1  A: 

For a Ruby IDE, try NetBeans.

epochwolf
NetBeans is one of the best IDEs I've ever used for any language, hands down. Its Ruby support is spectacular.
The Wicked Flea
I use NetBeans when I must use Windows or Linux. I use TextMate on my Mac. I don't need IDE support when I have a nice tool like that :)
epochwolf
+1  A: 

For simple but powerful use ado and ruby on windows.This is a really good example.

Jonke
+1  A: 

Be warned that the ODBC drivers included with the One-Click Installer for Ruby don't seem to be Unicode aware. (Accessing a SQL Server database from Unix, I used FreeTDS to convert UTF-16 to UTF-8 prior to getting it from UnixODBC.) I haven't been able to make a similar conversion in Windows.

Austin Ziegler