connecting to an oracle database

Discussion in 'Ruby' started by ruud grosmann, Feb 5, 2009.

  1. hi group,

    I have problems connection to an oracle database using dbi.

    machine: debian lenny,
    ruby: ruby 1.8.7 (2008-08-11 patchlevel 72)

    Using several descriptions on internet I have downloaded
    ruby-oci8-1.0.3.tar and installed it.

    The result is that I can open a database using a OCI8 object, but not
    using a DBI object. I understood that the way to use DBI is by
    installing that package.

    Following a test script and its output. Can someone tell me what could
    be wrong? Do I need to install another package?

    thanks in advance, Ruud


    ============ script
    require 'oci8'
    require 'dbi'

    connection = OCI8.new( 'user', 'pwd', 'database')
    cursor = connection.exec('select id, description, name from role')
    while r = cursor.fetch()
    puts r.join(',')
    end
    cursor.close
    connection.logoff

    puts "and now using DBI"

    puts DBI.available_drivers
    db = DBI.connect('DBI:OCI8:database', 'user', 'pwd')
    sql = "select id from role"

    dbh.select_all(sql) do | row |
    p row
    end

    dbh.disconnect

    ==============output
    1,admin,admin
    2,traffic,traffic
    and now using DBI
    dbi:ODBC:
    /usr/lib/ruby/1.8/DBD/ODBC/ODBC.rb:95:in `connect': IM002 (0)
    [iODBC][Driver Manager]Data source name not found and no default
    driver specified. Driver could not be loaded (DBI::DatabaseError)
    from /usr/lib/ruby/1.8/dbi.rb:424:in `connect'
    from /usr/lib/ruby/1.8/dbi.rb:215:in `connect'
    from leesdb:18
    ruud grosmann, Feb 5, 2009
    #1
    1. Advertising

  2. 2009/2/5 ruud grosmann <>:
    > hi group,
    >
    > I have problems connection to an oracle database using dbi.
    >
    > machine: debian lenny,
    > ruby: ruby 1.8.7 (2008-08-11 patchlevel 72)
    >
    > Using several descriptions on internet I have downloaded
    > ruby-oci8-1.0.3.tar and installed it.
    >
    > The result is that I can open a database using a OCI8 object, but not
    > using a DBI object. I understood that the way to use DBI is by
    > installing that package.
    >
    > Following a test script and its output. Can someone tell me what could
    > be wrong? Do I need to install another package?
    >
    > thanks in advance, Ruud
    >
    >
    > ============ script
    > require 'oci8'
    > require 'dbi'
    >
    > connection = OCI8.new( 'user', 'pwd', 'database')
    > cursor = connection.exec('select id, description, name from role')
    > while r = cursor.fetch()
    > puts r.join(',')
    > end
    > cursor.close
    > connection.logoff
    >
    > puts "and now using DBI"
    >
    > puts DBI.available_drivers
    > db = DBI.connect('DBI:OCI8:database', 'user', 'pwd')
    > sql = "select id from role"
    >
    > dbh.select_all(sql) do | row |
    > p row
    > end
    >
    > dbh.disconnect
    >
    > ==============output
    > 1,admin,admin
    > 2,traffic,traffic
    > and now using DBI
    > dbi:ODBC:
    > /usr/lib/ruby/1.8/DBD/ODBC/ODBC.rb:95:in `connect': IM002 (0)
    > [iODBC][Driver Manager]Data source name not found and no default
    > driver specified. Driver could not be loaded (DBI::DatabaseError)
    > from /usr/lib/ruby/1.8/dbi.rb:424:in `connect'
    > from /usr/lib/ruby/1.8/dbi.rb:215:in `connect'
    > from leesdb:18#


    Note, I am not using DBI just trying to throw in my 0.02EUR Oracle knowledge.

    Looks like it attempts to not use OCI but ODBC instead. Did you check
    output of these:

    DBI.available_drivers
    DBI.data_sources( driver )

    You could also try DBI.trace to get more interesting output.

    Btw, you do have an Oracle client installed, do you?

    Kind regards

    robert

    --
    remember.guy do |as, often| as.you_can - without end
    Robert Klemme, Feb 5, 2009
    #2
    1. Advertising

  3. The output of DBI.available_drivers is in my first mail. OCI8 is not
    available. But I was convinced that installing ruby-oci8 would install
    the OCI8-dbd. That is not true, apparently.

    I was wondering why and what I have to do to get it installed.

    I have the full Oracle client installed.

    thanks for helping, Ruud

    On 05/02/2009, Robert Klemme <> wrote:
    > 2009/2/5 ruud grosmann <>:
    >> hi group,
    >>
    >> I have problems connection to an oracle database using dbi.
    >>
    >> machine: debian lenny,
    >> ruby: ruby 1.8.7 (2008-08-11 patchlevel 72)
    >>
    >> Using several descriptions on internet I have downloaded
    >> ruby-oci8-1.0.3.tar and installed it.
    >>
    >> The result is that I can open a database using a OCI8 object, but not
    >> using a DBI object. I understood that the way to use DBI is by
    >> installing that package.
    >>
    >> Following a test script and its output. Can someone tell me what could
    >> be wrong? Do I need to install another package?
    >>
    >> thanks in advance, Ruud
    >>
    >>
    >> ============ script
    >> require 'oci8'
    >> require 'dbi'
    >>
    >> connection = OCI8.new( 'user', 'pwd', 'database')
    >> cursor = connection.exec('select id, description, name from role')
    >> while r = cursor.fetch()
    >> puts r.join(',')
    >> end
    >> cursor.close
    >> connection.logoff
    >>
    >> puts "and now using DBI"
    >>
    >> puts DBI.available_drivers
    >> db = DBI.connect('DBI:OCI8:database', 'user', 'pwd')
    >> sql = "select id from role"
    >>
    >> dbh.select_all(sql) do | row |
    >> p row
    >> end
    >>
    >> dbh.disconnect
    >>
    >> ==============output
    >> 1,admin,admin
    >> 2,traffic,traffic
    >> and now using DBI
    >> dbi:ODBC:
    >> /usr/lib/ruby/1.8/DBD/ODBC/ODBC.rb:95:in `connect': IM002 (0)
    >> [iODBC][Driver Manager]Data source name not found and no default
    >> driver specified. Driver could not be loaded (DBI::DatabaseError)
    >> from /usr/lib/ruby/1.8/dbi.rb:424:in `connect'
    >> from /usr/lib/ruby/1.8/dbi.rb:215:in `connect'
    >> from leesdb:18#

    >
    > Note, I am not using DBI just trying to throw in my 0.02EUR Oracle
    > knowledge.
    >
    > Looks like it attempts to not use OCI but ODBC instead. Did you check
    > output of these:
    >
    > DBI.available_drivers
    > DBI.data_sources( driver )
    >
    > You could also try DBI.trace to get more interesting output.
    >
    > Btw, you do have an Oracle client installed, do you?
    >
    > Kind regards
    >
    > robert
    >
    > --
    > remember.guy do |as, often| as.you_can - without end
    >
    >
    ruud grosmann, Feb 5, 2009
    #3
  4. Please do not top post.

    2009/2/5 ruud grosmann <>:
    > The output of DBI.available_drivers is in my first mail.


    Oh, I overlooked that one. Sorry.

    > OCI8 is not
    > available. But I was convinced that installing ruby-oci8 would install
    > the OCI8-dbd. That is not true, apparently.


    Maybe you need to additionally require something like dbi/oci8 - it's
    been a while that I used that so my memory may fail me here.

    Cheers

    robert

    --
    remember.guy do |as, often| as.you_can - without end
    Robert Klemme, Feb 5, 2009
    #4
  5. > Maybe you need to additionally require something like dbi/oci8 - it's
    > been a while that I used that so my memory may fail me here.


    I am sorry to have made a mess of my code example + output. The output
    is a cut and past of two different versions. In the output, the ODBC
    driver was mentioned, while I didn't use it in the script.
    It should read

    dbi:ODBC:
    /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:312:in `load_driver': Could
    not load driver (uninitialized constant OCI8::Driver)
    (DBI::InterfaceError)
    from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:154:in `_get_full_driver'
    from /usr/local/lib/ruby/site_ruby/1.8/dbi.rb:139:in `connect'
    from leeseb4:18

    The problem is solved now; I have put OCI8.rb in the db folder and got
    it from ttp://ruby-oci8.rubyforge.org/svn/branches/ruby-oci8-1.0/lib/dbd/OCI8.rb

    Thanks for helping,

    Ruud

    On 05/02/2009, Robert Klemme <> wrote:
    > Please do not top post.
    >
    > 2009/2/5 ruud grosmann <>:
    >> The output of DBI.available_drivers is in my first mail.

    >
    > Oh, I overlooked that one. Sorry.
    >
    >> OCI8 is not
    >> available. But I was convinced that installing ruby-oci8 would install
    >> the OCI8-dbd. That is not true, apparently.

    >
    > Maybe you need to additionally require something like dbi/oci8 - it's
    > been a while that I used that so my memory may fail me here.
    >
    > Cheers
    >
    > robert
    >
    > --
    > remember.guy do |as, often| as.you_can - without end
    >
    >
    ruud grosmann, Feb 5, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Juha Laiho
    Replies:
    0
    Views:
    525
    Juha Laiho
    Jul 30, 2003
  2. David Rudder
    Replies:
    0
    Views:
    393
    David Rudder
    Jul 30, 2003
  3. Replies:
    1
    Views:
    3,886
    wes weston
    Mar 5, 2004
  4. yahibble
    Replies:
    1
    Views:
    261
    Grig Gheorghiu
    Jul 21, 2005
  5. Feyruz
    Replies:
    4
    Views:
    2,131
    Sherm Pendley
    Oct 14, 2005
Loading...

Share This Page