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?
kkbenjAsked:
Who is Participating?
 
wilcoxonCommented:
darling39 is incorrect.  It should be $DBI::errstr (with two colons).  After it is connected, it should be $dbh->errstr (or some other appropriate handle $var).
0
 
kkbenjAuthor Commented:
That code was my first attempt at connecting to Oracle.  Need to connect to both, although my question right now concerns SQL Server
0
 
wilcoxonCommented:
I believe the issue is that your die statement has $DBI:errstr - it should be $DBI::errstr (two colons).
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
darling39Commented:
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
0
 
kkbenjAuthor Commented:
darling39 - I tried this but still get the Global symbol "$DBI" requires explicit package name
0
 
kkbenjAuthor Commented:
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?
0
 
wilcoxonCommented:
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).
0
 
kkbenjAuthor Commented:
Thanks for all of your help and patience.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.