Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Unable to connect to Oracle 19c

by SpaceCowboy (Acolyte)
on Nov 24, 2021 at 05:19 UTC ( #11139069=perlquestion: print w/replies, xml ) Need Help??

SpaceCowboy has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

Perl newbie here. I have a windows 10 machine, with Strawberry Perl installed (5.32.1 - Jan 2021 release) that apparently comes preloaded with DBI and DBD::Oracle driver. however, I am unable to connect with my local oracle 19c instance that I have on my machine.

I researched some questions and they all seem to point to installing a 32-bit oracle client, that is no longer available to download. Please can you help. Here is my code:

# database connector # load all the libraries use DBI; use warnings; # print("\n\n\tA\n\n"); my @drivers = DBI->available_drivers(); =pod foreach my $driver (@drivers) { print ("$driver \n "); my @dataSources = DBI->data_sources($driver); foreach my $datasource (@dataSources) { print("\t $datasource\n"); } } =cut $dbname = "orcl"; $driver = "oracle"; $host = "localhost"; $username = "meeee"; $password = "000000000000"; $dsn = "dbi:oracle:orcl;host=$host;port=1539"; $dbh = DBI->connect("dbi:oracle:host=localhost;port=1539",$username,$p +assword) or die $DBI::errstr; exit;

and here is the output I received

Name "main::driver" used only once: possible typo at .\ l +ine 21. Name "main::dsn" used only once: possible typo at .\ line +25. Name "main::dbh" used only once: possible typo at .\ line +27. Name "main::dbname" used only once: possible typo at .\ li +ne 20. DBD::oracle initialisation failed: Can't locate object method "driver" + via package "DBD::oracle" at C:/Strawberry/perl/vendor/lib/ li +ne 829. Perhaps the capitalisation of DBD 'oracle' isn't right. at .\dbconnect line 27.


The connection string needs 'Oracle' to be mentioned, along with the datatabse SID in connection string.

Also, there seems to be legacy documentations that suggests installing Oracle Instant Client, Visual C++ distributable and Windows SDK to get Perl/DBD::Oracle interact with a oracle database in windows operating system.

I did not do any of these and yet it worked for me with Strawberry Perl 5.32.1 (Jan 2021). So please consider the environment before moving to installing a bunch of dependencies which one may or may not need/be applicable anymore. I already wasted time and effort attempting to locate legacy drivers and SDKs that was never needed.

Replies are listed 'Best First'.
Re: Unable to connect to Oracle 19c
by kcott (Archbishop) on Nov 24, 2021 at 07:51 UTC

    G'day SpaceCowboy,

    There's multiple issues:

    • Put use strict; at the top of all of your Perl code. In this case, it will highlight many lines that need to start with my.
    • POD directives should be surrounded by blank lines. That's not an absolute requirement, but is needed in some cases, so it's best to do it everywhere. See "perlpod: Hints for Writing Pod".
    • See "DBD::Oracle - connect()". It shows multiple formats, none of which match what you've coded.

    — Ken

Re: Unable to connect to Oracle 19c
by bliako (Monsignor) on Nov 24, 2021 at 09:10 UTC

    note that your $dsn is not used in your DBI->connect() which hardcodes the dsn.

    Check if DBD::Oracle is installed under a path included in @INC. In Linux I use App::whichpm to locate modules from the command prompt, like: whichpm DBD::Oracle . In order to see Perl's @INC I do this from command prompt: perl -e "print \"@INC\"" (I guess that works in windows with lame quoting rules). Simply check if the starting path of the first command matches an entry in the output of the second.

    Finally, as you said and other Monks said and the program diagnosed: Perhaps the capitalisation of DBD 'oracle' isn't right. And also the documentation of DBD::Oracle has this example (and that should have been your first call actually!):

    use DBI; $dbh = DBI->connect("dbi:Oracle:$dbname", $user, $passwd);

    Also note that more than one reasons for failure may apply.

    bw, bliako

      You can get the App::whichpm behavior from perldoc as well, with -l

      See also, perldoc -m for jumping straight into the code of a module.

      Thank you @bliako, turns out that it needed my SID. Which was never the case with MySQL when I tested with it.

      It is working now. Sorry for posting somewhat trivial question...
Re: Unable to connect to Oracle 19c
by Anonymous Monk on Nov 24, 2021 at 07:21 UTC
    Perhaps the capitalisation of DBD 'oracle' isn't right. at .\dbconnect

    Try Oracle

      yes, it worked. I also edited my question to include solution. grateful, if you can have a look and let me know if what I have wrote needs revision

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11139069]
Approved by kcott
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2023-12-11 03:08 GMT
Find Nodes?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?

    Results (41 votes). Check out past polls.