connecting to Oracle using OCI8 and DBI

Discussion in 'Ruby' started by Peter Bailey, Apr 13, 2009.

  1. Peter Bailey

    Peter Bailey Guest

    Hi,
    I need to access an Oracla database with Ruby. I've loaded OCI8 and DBI.
    When I run a simple script to just check on the existence of an image in
    the database, I get a DBI interface error, and, this:

    Exception: Could not load driver (unitialized constant OCI8::Driver)

    Can someone help?
    Thanks a lot,
    Peter
    --
    Posted via http://www.ruby-forum.com/.
     
    Peter Bailey, Apr 13, 2009
    #1
    1. Advertising

  2. On Mon, Apr 13, 2009 at 9:35 PM, Peter Bailey <> wrote:
    > Hi,
    > I need to access an Oracla database with Ruby. I've loaded OCI8 and DBI.
    > When I run a simple script to just check on the existence of an image in
    > the database, I get a DBI interface error, and, this:
    >
    > Exception: Could not load driver (unitialized constant OCI8::Driver)


    What version of ruby, ruby-dbi and ruby-oci8 do you use?
    How did you install ruby-dbi and ruby-oci8?
     
    KUBO Takehiro, Apr 14, 2009
    #2
    1. Advertising

  3. Peter Bailey

    Peter Bailey Guest

    Takehiro Kubo wrote:
    > On Mon, Apr 13, 2009 at 9:35 PM, Peter Bailey <> wrote:
    >> Hi,
    >> I need to access an Oracla database with Ruby. I've loaded OCI8 and DBI.
    >> When I run a simple script to just check on the existence of an image in
    >> the database, I get a DBI interface error, and, this:
    >>
    >> Exception: Could not load driver (unitialized constant OCI8::Driver)

    >
    > What version of ruby, ruby-dbi and ruby-oci8 do you use?
    > How did you install ruby-dbi and ruby-oci8?


    Thanks,
    I'm using Ruby 1.8.6. I did a gem install of dbi, so, presumably, it's
    the latest. And, I downloaded and installed the latest version of oci8,
    for Windows.

    A colleague of mine suggested that, for my purposes, I can just use http
    to query my database. So, I've done that and it works. But, I would like
    to understand better how to actually get into the database, because, in
    the future, I could foresee needing to actually pull files from it.
    --
    Posted via http://www.ruby-forum.com/.
     
    Peter Bailey, Apr 14, 2009
    #3
  4. Hi,

    On Wed, Apr 15, 2009 at 12:09 AM, Peter Bailey <> wrote:
    >>> Exception: Could not load driver (unitialized constant OCI8::Driver)


    Did you manually edit dbi.rb?
    The OCI8 Driver defines DBI::DBD::OCI8::Driver, but not OCI8::Driver.

    >> What version of ruby, ruby-dbi and ruby-oci8 do you use?
    >> How did you install ruby-dbi and ruby-oci8?

    >
    > Thanks,
    > I'm using Ruby 1.8.6. I did a gem install of dbi, so, presumably, it's
    > the latest. And, I downloaded and installed the latest version of oci8,
    > for Windows.


    ruby-dbi 0.4.1?
    ruby-oci8 2.0.1 or 1.0.5?

    Could you tell me the result of the following command on the irb console?

    require 'dbi'
    DBI::VERSION
    require 'oci8'
    OCI8::VERSION
    dbd_dr = DBI::DBD.const_get:)OCI8)
    dbd_dr::Driver.new
    DBI.connect('dbi:OCI8:', 'username', 'password')

    Copy and paste the output as follows:

    c:\> irb
    irb(main):001:0> require 'dbi'
    => true
    irb(main):002:0> DBI::VERSION
    => "0.4.1"
    irb(main):003:0> require 'oci8'
    => true
    irb(main):004:0> OCI8::VERSION
    => "2.0.1"
    irb(main):005:0> dbd_dr = DBI::DBD.const_get:)OCI8)
    => DBI::DBD::OCI8
    irb(main):006:0> dbd_dr::Driver.new
    => #<DBI::DBD::OCI8::Driver:0xf7a1bb3c>
    irb(main):007:0> DBI.connect('dbi:OCI8:', 'username', 'password')
    => #<DBI::DatabaseHandle:0xf7a13310 @driver_name="OCI8",
    @trace_mode=nil, @convert_types=true,
    @handle=#<DBI::DBD::OCI8::Database:0xf7a13220 @attr={},
    @handle=#<OCI8:RUBY>>, @trace_output=nil>
    irb(main):008:0>
     
    KUBO Takehiro, Apr 15, 2009
    #4
  5. Peter Bailey

    Peter Bailey Guest

    Peter Bailey, Apr 15, 2009
    #5
  6. On Wed, Apr 15, 2009 at 10:34 PM, Peter Bailey <> wrote:
    > DBI is version 0.1.1.
    > OCI8 is version 1.0.5


    Thanks.
    What about other information I requested in my previous reply?
     
    KUBO Takehiro, Apr 15, 2009
    #6
  7. Peter Bailey

    Peter Bailey Guest

    Takehiro Kubo wrote:
    > On Wed, Apr 15, 2009 at 10:34 PM, Peter Bailey <> wrote:
    >> DBI is version 0.1.1.
    >> OCI8 is version 1.0.5

    >
    > Thanks.
    > What about other information I requested in my previous reply?


    F:\workflows\graphics>irb
    irb(main):001:0> require 'dbi'
    => true
    irb(main):002:0> require 'oci8'
    => true
    irb(main):003:0> dbd_dr = DBI::DBD.const_get:)OCI8)
    => OCI8
    irb(main):004:0> dbd_dr::Driver.new
    NameError: uninitialized constant OCI8::Driver
    from (irb):4
    irb(main):005:0> DBI.conect('dbi::OCI8:', 'orcauser', 'orca2user')
    NoMethodError: undefined method `conect' for DBI:Module
    from (irb):5
    irb(main):006:0>
    --
    Posted via http://www.ruby-forum.com/.
     
    Peter Bailey, Apr 15, 2009
    #7
  8. On Wed, Apr 15, 2009 at 11:26 PM, Peter Bailey <> wrote:
    > Takehiro Kubo wrote:
    >> On Wed, Apr 15, 2009 at 10:34 PM, Peter Bailey <> wrote:
    >>> DBI is version 0.1.1.


    The latest dbi is 0.4.1. You would use dbi bundled with One Click Ruby
    Installer.

    >>> OCI8 is version 1.0.5

    >>
    >> Thanks.
    >> What about other information I requested in my previous reply?

    >
    > F:\workflows\graphics>irb
    > irb(main):001:0> require 'dbi'
    > =3D> true
    > irb(main):002:0> require 'oci8'
    > =3D> true
    > irb(main):003:0> dbd_dr =3D DBI::DBD.const_get:)OCI8)
    > =3D> OCI8


    I have thought that DBI::DBD.const_get:)OCI8) would return DBI::DBD::OCI8 a=
    nd
    it would raise an exception if DBI::DBD::OCI8 is not defined. But it
    returns OCI8
    if DBI::DBD::OCI8 is not found. I have misunderstood.

    > irb(main):004:0> dbd_dr::Driver.new
    > NameError: uninitialized constant OCI8::Driver
    > =A0 =A0 =A0 =A0from (irb):4
    > irb(main):005:0> DBI.conect('dbi::OCI8:', 'orcauser', 'orca2user')
    > NoMethodError: undefined method `conect' for DBI:Module
    > =A0 =A0 =A0 =A0from (irb):5
    > irb(main):006:0>


    You did a typo. Use 'connect' instead of 'conect'.
    DBI.connect will be raise the following exception when using dbi 0.1.1
    and oci8 1.0.5.
    DBI::InterfaceError: Could not load driver (no such file to load
    -- DBD/OCI8/OCI8)
    Did you copy oci8.rb to DBD/OCI8/OCI8.rb?

    You have two ways to use dbi and Oracle.
    1. Use the latest dbi instead of 0.1.1.
    Add "require 'rubygems'" prior to "require 'dbi'".
    Otherwise,
    2. Copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.
     
    KUBO Takehiro, Apr 15, 2009
    #8
  9. > You have two ways to use dbi and Oracle.
    > 1. Use the latest dbi instead of 0.1.1.
    > =A0 =A0Add "require 'rubygems'" prior to "require 'dbi'".
    > Otherwise,
    > 2. Copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.


    Yet another way:
    3. Use One-Click Installer 1.8.6-27 Release Candidate 2
    The bundled dbi version is 0.2.2.
    You have no need to copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.
     
    KUBO Takehiro, Apr 15, 2009
    #9
  10. Peter Bailey

    Peter Bailey Guest

    Takehiro Kubo wrote:
    >> You have two ways to use dbi and Oracle.
    >> 1. Use the latest dbi instead of 0.1.1.
    >> � �Add "require 'rubygems'" prior to "require 'dbi'".
    >> Otherwise,
    >> 2. Copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.

    >
    > Yet another way:
    > 3. Use One-Click Installer 1.8.6-27 Release Candidate 2
    > The bundled dbi version is 0.2.2.
    > You have no need to copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.


    Yeh, well, I don't see any one-click installer for 1.8.6-27, only 1.8.6.
    And, that's what I've been using. And, if I go to these web sites and
    choose the latest oci8 and dbi, I don't see why it just doesn't work.
    So, for now, I'm just giving up. Thanks.

    --
    Posted via http://www.ruby-forum.com/.
     
    Peter Bailey, Apr 15, 2009
    #10
  11. On Thu, Apr 16, 2009 at 1:44 AM, Peter Bailey <> wrote:
    > Takehiro Kubo wrote:
    >>> You have two ways to use dbi and Oracle.
    >>> 1. Use the latest dbi instead of 0.1.1.
    >>> Add "require 'rubygems'" prior to "require 'dbi'".


    Gem packages are unavailable unless "require 'rubygems'".

    >>> Otherwise,
    >>> 2. Copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.

    >>
    >> Yet another way:
    >> 3. Use One-Click Installer =A01.8.6-27 Release Candidate 2
    >> =A0 =A0The bundled dbi version is 0.2.2.
    >> =A0 =A0You have no need to copy dbd/OCI8.rb to DBD/OCI8/OCI8.rb.

    >
    > Yeh, well, I don't see any one-click installer for 1.8.6-27, only 1.8.6.


    What I said is ruby186-27_rc2.exe in the following link.
    http://rubyforge.org/frs/?group_id=3D167

    > And, that's what I've been using.


    Your dbi version is 0.1.1. It means your are using ruby186-26.exe or earlie=
    r.
     
    KUBO Takehiro, Apr 16, 2009
    #11
  12. Takehiro Kubo wrote:
    > Hi,
    >
    > On Wed, Apr 15, 2009 at 12:09 AM, Peter Bailey <> wrote:
    >>>> Exception: Could not load driver (unitialized constant OCI8::Driver)

    >
    > Did you manually edit dbi.rb?
    > The OCI8 Driver defines DBI::DBD::OCI8::Driver, but not OCI8::Driver.
    >
    >>> What version of ruby, ruby-dbi and ruby-oci8 do you use?
    >>> How did you install ruby-dbi and ruby-oci8?

    >>
    >> Thanks,
    >> I'm using Ruby 1.8.6. I did a gem install of dbi, so, presumably, it's
    >> the latest. And, I downloaded and installed the latest version of oci8,
    >> for Windows.

    >
    > ruby-dbi 0.4.1?
    > ruby-oci8 2.0.1 or 1.0.5?
    >
    > Could you tell me the result of the following command on the irb
    > console?
    >
    > require 'dbi'
    > DBI::VERSION
    > require 'oci8'
    > OCI8::VERSION
    > dbd_dr = DBI::DBD.const_get:)OCI8)
    > dbd_dr::Driver.new
    > DBI.connect('dbi:OCI8:', 'username', 'password')
    >
    > Copy and paste the output as follows:
    >
    > c:\> irb
    > irb(main):001:0> require 'dbi'
    > => true
    > irb(main):002:0> DBI::VERSION
    > => "0.4.1"
    > irb(main):003:0> require 'oci8'
    > => true
    > irb(main):004:0> OCI8::VERSION
    > => "2.0.1"
    > irb(main):005:0> dbd_dr = DBI::DBD.const_get:)OCI8)
    > => DBI::DBD::OCI8
    > irb(main):006:0> dbd_dr::Driver.new
    > => #<DBI::DBD::OCI8::Driver:0xf7a1bb3c>
    > irb(main):007:0> DBI.connect('dbi:OCI8:', 'username', 'password')
    > => #<DBI::DatabaseHandle:0xf7a13310 @driver_name="OCI8",
    > @trace_mode=nil, @convert_types=true,
    > @handle=#<DBI::DBD::OCI8::Database:0xf7a13220 @attr={},
    > @handle=#<OCI8:RUBY>>, @trace_output=nil>
    > irb(main):008:0>



    I followd your steps . But while connecting .

    DBI.connect('dbi:OCI8:databasename:ipaddress', 'username', 'password')

    I got following error

    DBI::DatabaseError: ORA-12154: TNS:could not resolve the connect
    identifier specified

    --
    Posted via http://www.ruby-forum.com/.
     
    Vetrivel Vetrivel, Nov 30, 2009
    #12
    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. ulloa
    Replies:
    1
    Views:
    537
    Juha Laiho
    Jul 22, 2004
  2. Ben Edwards
    Replies:
    1
    Views:
    84
  3. Dheeraj Gambhir
    Replies:
    0
    Views:
    148
    Dheeraj Gambhir
    Jul 27, 2009
  4. Tim
    Replies:
    8
    Views:
    157
    Peter J. Holzer
    Dec 15, 2007
  5. ankur srivastava

    ERR In Connecting Oracle DB using OCI8 gem

    ankur srivastava, Jun 17, 2013, in forum: Ruby
    Replies:
    1
    Views:
    255
    Simon Krahnke
    Jun 17, 2013
Loading...

Share This Page