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


Solution

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.

In reply to Unable to connect to Oracle 19c by SpaceCowboy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.