#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Edinburgh, UK
    Posts
    84
    Rep Power
    12

    Connecting to MS SQL with RUby


    Hi There

    can anyone give me a very basic example of using Ruby to connect to an MS SQL server, along with a basic example of of a select query?

    I have been trawling the Internet in vain, none of the examples I have tried so far have worked at all and I am starting to think this may be the wrong tool for the job...

    Cheers
    -
    K
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2004
    Location
    Constant Limbo
    Posts
    989
    Rep Power
    363
    In order to save us the trouble of duplicating your effort, what have you tried and what error messages have you received indicating that 'it' did not work?

    Until then, here are the top three hits I get from google (each with an example)
    one
    two
    three
    True happiness is not getting what you want, it's wanting what you've already got.

    My Blog
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Edinburgh, UK
    Posts
    84
    Rep Power
    12
    actually answered some of my own question already with this:

    Code:
    require 'dbi'
    oConn = DBI.connect('DBI:ADO:Provider=SQLNCLI;Data Source="YOUR_DB_NAME";User ID="YOUR_DB_USERNAME";password="YOUR_DB_PASSWORD"')
    oConn.select_all('YOUR_SQL_STATEMENT'){|row| puts row}
    This will print everything on the screen in quite a messy way, everything is put on a new line - which is my next task

    Any comments greatly appreciated - I have a feeling that Ruby and MS SQL is pretty much not used at the moment together, something I will assume changing when IronRuby debuts...

IMN logo majestic logo threadwatch logo seochat tools logo