Robot Has No Heart

Xavier Shay blogs here

A robot that does not have a heart

Rails 3, Ruby 1.9.2, Windows 2008, and SQL Server 2008 Tutorial

This took me a while to figure out, especially since I’m not so great with either windows or SQL server, but in the end the process isn’t so difficult.

Rails 3, Ruby 1.9.2, Windows 2008, and SQL Server 2008 Screencast

The steps covered in this screencast are:

  1. Create user
  2. Create database
  3. Give user permissions
  4. Create DSN
  5. Install ruby
  6. Install devkit (Needed to complie native extensions for ODBC)
  7. Create a new rails app
  8. Add activerecord-sqlserver-adapter and ruby-odbc to Gemfile
  9. Customize config/database.yml
1
2
3
4
5
6
7
8
# config/database.yml
development:
  adapter: sqlserver
  dsn: testdsn_user
  mode: odbc
  database: test
  username: xavier
  password:

Some errors you may encounter:

The specified module could not be found – odbc.so You have likely copied odbc.so from i386-msvcrt-ruby-odbc.zip. This is for 1.8.7, and does not work for 1.9. Remove the .so file, and install ruby-odbc as above.

The specified DSN contains an architecture mismatch between the Driver and the Application. Perhaps you have created a system DSN. Try creating a user DSN instead. I also found some suggestions that you need to use a different version of the ODBC configuration panel, but this wasn’t relevant for me.

  1. Rick says:

    that's one blazin' fast win 2008 server!

  2. Xavier Shay says:

    That's what happens when you run it on a MacBook Pro ;)

    (or you know, edit out the slow bits...)

  3. Carl Hörberg says:

    Checkout ironruby and the adonet mode instead, much faster and easier than odbc.. http://github.com/rails-sqlserver/activerecord-sqlserver-adapter
    http://ironruby.net/

  4. Xavier Shay says:

    Carl, I've been hearing that IronRuby is pretty much dead. I'm going down the JRuby path (probably will switch to JDBC drivers then, I imagine). Do you have evidence contrary? Are you running Rails on IronRuby in production?

  5. Ken Collins says:

    I always love sharing good info! I added your article as a link from the adapter's wiki page here http://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/Platform-Installation---Windows

  6. eddie cianci says:

    Xavier, I assume you're still using webrick for development, but how are you hosting in production? Are you using IIS?

  7. Ruprict says:

    +1 for Eddie's question. Figuring out a way to get IIS to serve Rails is my Everest (I have failed billions of times).

    I tried it with IronRuby, but it was not easy and I never completely got it working. Also heard that IronRuby is dead, with 2 of the main IronRuby doods leaving Microsoft.

    If you can get a somewhat easy-to-deploy IIS solution going, I will sing your praises from the mountaintops. Or something.

    Great post,
    Ruprict

  8. Xavier Shay says:

    Not in production yet, pretty sure I'm going to use jRuby with glassfish. There will definitely be a post about that!

  9. http://aikr473.myopenid.com/ says:

    Thanks, really helped me out.

  10. Marco Mastrodonato says:

    I'm making a new production 2008 r2 server and i've figured out that iis7 could manage rails in fastcgi:
    http://blogs.iis.net/ruslany/archive/2008/08/07/ruby-on-rails-in-iis-7-0-with-url-rewriter.aspx

  11. http://gobb0.myopenid.com says:

    Have you tried connecting to SQL Azure using the above setup? (ie Rails 3, Ruby 1.9.2, Windows 2008, and SQL Server 2008 and also i'm using activerecord-sqlserver-adapter 3.0.9 found here https://github.com/rails-sqlserver/activerecord-sqlserver-adapter).

    After some searching I found:

    http://blogs.msdn.com/b/mcsuksoldev/archive/2010/02/26/9969876.aspx

    but it doesn't seem to work with the above setup.

  12. Xavier Shay says:

    I haven't tried, and no longer have the setup to try. Let us know if you win.

  13. aaron_mertes says:

    This was a much needed video, thank you so much for putting this out for all to learn from!

  14. Luke says:

    Hey guys,

    Just to add for production this looks like it'll work nicely:

    http://www.helicontech.com/articles/run-django-apps-on-iis/

    Bear in mind it will install Ruby as part of the install, and you need to bundle install before running the app. Nice easy setup though.

    In the BlankRubyOnRails project folder there is a web_config.xml file that you can copy to any of your other apps. Just change the port to 80 in the settings if you wanted to use it in production.

    Kind Regards
    Luke

  15. Beasty says:

    Amazing! This post finally helps me after googlin' for hours :)

  16. Beasty says:

    Can I link to your post in my own blog? (just to spread this good tutorial)

  17. Xavier Shay says:

    Don't need to ask permission to link :)

  18. Jett says:

    Hi Xavier,

    Thanks for this great article. I have followed every step but I am stuck on the part where I need to create DSN. Specifically the dialog where I select "With SQL Server authentication using a login ID ...". The checkbox "Connect to SQL Server to obtain default settings ..." is checked. Login ID: is "jett" which I just created and set permissions as you described. But when I click Next I get the error below:
    Microsoft SQL Server Login
    Connection failed:
    SQL State: '28000'
    SQL Server Error: 18456
    [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'jett'

    I am using SQL Server Express 2008 R2. I get similar error when I try connecting manually in SQL Server Management Studio to .\SQLEXPRESS server using the same login account (jett).

    Any help will be greatly appreciated.

    Thanks,
    Jett

  19. beast says:

    @jett, whats up with the password`?

  20. Jett says:

    @ beast, I didn't use any password as described in the tutorial. I did exactly same thing in the tutorial. I even tried doing the steps to the letter. I created user xavier with no password, testdb and mydsn.. Still didn't work.

    I also tried using C:\Windows\SysWOW64\odbcad32.exe to create the DSN didn't do the trick.

    I use SQL Server Express 2008 R2 on Windows 7 64 bit.

  21. Jett says:

    Never mind guys. I fixed my issue by uninstalling and reinstalling SQL Server Express.

  22. alberto says:

    Thanks you rock!!!

Post a comment


(lesstile enabled - surround code blocks with ---)

A pretty flower Another pretty flower