Link to home
Start Free TrialLog in
Avatar of kkbenj
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:db_name','username','password',{RaiseError=>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?
Avatar of kkbenj
kkbenj

ASKER

That code was my first attempt at connecting to Oracle.  Need to connect to both, although my question right now concerns SQL Server
Avatar of wilcoxon
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
Avatar of kkbenj

ASKER

darling39 - I tried this but still get the Global symbol "$DBI" requires explicit package name
ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kkbenj

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?
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).
Avatar of kkbenj

ASKER

Thanks for all of your help and patience.