Accessing database using ruby-odbc

938 views
Skip to first unread message

eslibr...@gmail.com

unread,
Apr 11, 2013, 3:55:59 AM4/11/13
to test...@googlegroups.com
Hello, 

I've been trying to connect to our database to retrieve some values to be used in my tests.
I need to install ruby-odbc gem to do that but I always get the error "Unable to load odbc..." when I try to install.

I installed ruby2.0 and the dbi, ruby-odbc gems and it worked perfect outside testwise. 
My question is 
1-) how can I use ruby2.0 and these gems in testwise. (I want to use this 2.0v instead of  the interpreter in C:\agileway\testwise\vendor\ruby\bin\ruby.exe)
or
2-) how can I connect to an mssql db using any odbc driver in testwise?


Thank you in advance, it's a really big problem not having the database connectivity.

Zhimin

unread,
Apr 11, 2013, 5:43:27 AM4/11/13
to test...@googlegroups.com
Hi,

Are you using TestWise Pro? To add new gem supports in TestWise.

1. Add gems into c:\agileway\TestWise\Gemfile

   gem "ruby-odbc" # for example

2. Copy new gems into TestWise

   gem folder to C:\agileway\TestWise\vendor\bundle\ruby\1.8\gems
   gem specification file (.gemspec) to C:\agileway\TestWise\vendor\bundle\ruby\1.8\specifications

TestWise run on 1.8, not supporting Ruby 2.0 yet.


> 2-) how can I connect to an mssql db using any odbc driver in testwise?

That's is not specific to TestWise IDE. You can write test script to connect to MySQL directly with 'mysql',  'dbi' gem. 

Cheers,
Zhimin


eslibr...@gmail.com

unread,
Apr 11, 2013, 3:33:50 PM4/11/13
to test...@googlegroups.com
Hello and thanks for your help.

I'm using community addition for now (and trying to show it's value to persuade the managers;) )

The methods you suggested didnt work. I still get the same error as following:

Failure/Error: conn = DBI.connect('dbi:ODBC:blaDSN', 'blauser', 'blapassword')
DBI::InterfaceError:
Unable to load driver 'ODBC' (underlying error: uninitialized constant DBI::DBD::ODBC)
# ./vendor/bundle/ruby/1.8/gems/dbi-0.4.5/lib/dbi.rb:300:in `load_driver'
# ./vendor/ruby/lib/ruby/1.8/monitor.rb:242:in `synchronize'
# ./vendor/bundle/ruby/1.8/gems/dbi-0.4.5/lib/dbi.rb:242:in `load_driver'
# ./vendor/bundle/ruby/1.8/gems/dbi-0.4.5/lib/dbi.rb:160:in `_get_full_driver'
# ./vendor/bundle/ruby/1.8/gems/dbi-0.4.5/lib/dbi.rb:145:in `connect'
# D:/TestOtomasyon/TestWisely_WS/OTT/genel_test.rb:42

Zhimin

unread,
Apr 11, 2013, 4:39:04 PM4/11/13
to test...@googlegroups.com
Hi, 

Sorry, I forgot one step: delete Gemfile.lock 

Anyway, I packaged ruby-odbc in latest TestWise Pro 3.8. 

  story "testing ODBC" do
    require 'odbc'
    require 'dbi'
    ODBC.connect("A", "B", "C")
    # DBI.connect('dbi:ODBC:blaDSN', 'blauser', 'blapassword')
  end

The output (in TestWise) below shows the DBI or ODBC class are loaded:

ODBC directly: 

  ODBC::Error:
  IM002 (0) [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
 
DBI with ODBC: 

  Failure/Error: DBI.connect('dbi:ODBC:blaDSN', 'blauser', 'blapassword')
  DBI::InterfaceError:
  Could not load driver (undefined method `driver_name' for ODBC:Module)
  # ./vendor/bundle/ruby/1.8/gems/dbi-0.4.5/lib/dbi.rb:318:in `load_driver'


>  trying to show it's value to persuade the managers;

Yes, I understand. Many motivated testers/programmers do that. Very few managers believe test automation actually after seeing so many failed tempts. Show them the working test scripts!

Cheers,
Zhimin   
Reply all
Reply to author
Forward
0 new messages