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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.