kkbenj
asked on
Perl connection to an SQL server database
I am just getting started with this connection to pull data out of the sql server database:
#!/usr/bin/perl
use strict;
use DBI;
my $dbh = DBI->connect('dbi:Oracle:d b_name','u sername',' password', {RaiseErro r=>1, AutoCommit=>0 }) || die "Database connection not made: $DBI:errstr";
-------------------------- ---------- ---------- ---------- ---------- ---------- ----------
I do have a DBI directory under \Perl\lib but get this error:
Global symbol "$DBI" requires explicit package name at dbconnect.pl line 6.
Execution of dbconnect.pl aborted due to compilation errors.
What am I missing?
#!/usr/bin/perl
use strict;
use DBI;
my $dbh = DBI->connect('dbi:Oracle:d
--------------------------
I do have a DBI directory under \Perl\lib but get this error:
Global symbol "$DBI" requires explicit package name at dbconnect.pl line 6.
Execution of dbconnect.pl aborted due to compilation errors.
What am I missing?
I believe the issue is that your die statement has $DBI:errstr - it should be $DBI::errstr (two colons).
Try this:
die "Database connection not made:" . $DBI->errstr";
you need to terminate the "Database connection not made" string and insert a dot to append the $DBI->errstr dot between the string and the output from DBI->errstr, Also note the syntax is DBI->errstr not DBI:errstr
die "Database connection not made:" . $DBI->errstr";
you need to terminate the "Database connection not made" string and insert a dot to append the $DBI->errstr dot between the string and the output from DBI->errstr, Also note the syntax is DBI->errstr not DBI:errstr
ASKER
darling39 - I tried this but still get the Global symbol "$DBI" requires explicit package name
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
wilcoxon - I changed to 2 colons. Thank you for explaining the difference.
Now I get a perl.exe pop up error:
This application has failed to start because OCI.dll was not found. Re-installing the application may fix this problem.
Shouldn't any connection failure be caught in die?
Now I get a perl.exe pop up error:
This application has failed to start because OCI.dll was not found. Re-installing the application may fix this problem.
Shouldn't any connection failure be caught in die?
Normally, yes. However, that popup is a Windows system error which I don't think can be caught at the application level. You are missing OCI.dll - a Google search (http://www.google.com/search?q=oci.dll) pulls up some promising looking pages (a free download, wikipedia entry, several questions (and hopefully answers) about missing oci.dll, etc).
ASKER
Thanks for all of your help and patience.
ASKER