http://qs321.pair.com?node_id=11139069

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 .\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.