LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-27-2010, 07:31 AM   #1
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
Connecting to remote oracle database using perl??


How to connect to remote oracle database using perl??
This is what I tried.
Code:
#usr/bin/perl 
use DBI;
use strict;
use warnings;
use DBI;
$ENV{ORACLE_SID}   = "oracle9i";
$ENV{ORACLE_HOME}  = "/opt/oracle";
my $dbname = "test";
my $dbuser = "test";
my $dbpass = "test";
my $dbh = DBI->connect("dbi:Oracle:host=192.168.1.99;$dbname", $dbuser, $dbpass)
             || die "Unable to connect to $dbname: $DBI::errstr\n";
But I am unable to connect.

Any help is highly appreciated

Last edited by ashok.g; 01-27-2010 at 08:06 AM.
 
Old 01-27-2010, 09:08 AM   #2
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: PC-BSD / FreeBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 438

Rep: Reputation: 57
Quote:
Originally Posted by ashok.g View Post
How to connect to remote oracle database using perl??
This is what I tried.
Code:
#usr/bin/perl 
use DBI;
use strict;
use warnings;
use DBI;
$ENV{ORACLE_SID}   = "oracle9i";
$ENV{ORACLE_HOME}  = "/opt/oracle";
my $dbname = "test";
my $dbuser = "test";
my $dbpass = "test";
my $dbh = DBI->connect("dbi:Oracle:host=192.168.1.99;$dbname", $dbuser, $dbpass)
             || die "Unable to connect to $dbname: $DBI::errstr\n";
But I am unable to connect.

Any help is highly appreciated
I do this quite a lot, here's how mine is set:

Code:
my $gDBH = DBI->connect("dbi:Oracle:$dbhost;sid=$dbsid;port=$dbport",$user,$pass) 
        or Fail_Out("Unable to connect: $DBI::errstr\n");
There is another method as well, that looks more 'oracle-ish':
Code:
  $dbh = DBI->connect('dbi:Oracle:', q{scott/tiger@(DESCRIPTION=
  (ADDRESS=(PROTOCOL=TCP)(HOST= foobar)(PORT=1521))
  (CONNECT_DATA=(SID=ORCL)))}, "")
Have you verified that you can get to the listening port (probably 1521) from wherever the script is running? It's possible there is a firewall or something preventing it.

I assume you checked the usual suspects - IP, password, user, listener status, port, etc.
 
Old 01-27-2010, 10:26 PM   #3
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by MBybee View Post
I do this quite a lot, here's how mine is set:

Have you verified that you can get to the listening port (probably 1521) from wherever the script is running? It's possible there is a firewall or something preventing it.

I assume you checked the usual suspects - IP, password, user, listener status, port, etc.
Actually I don't have any DBD::Oracle driver installed on my PC.
But I had it on my remote machine.Is that the problem?
 
Old 01-28-2010, 08:01 AM   #4
MBybee
Member
 
Registered: Jan 2009
Location: wherever I can make a living
Distribution: PC-BSD / FreeBSD / Debian / Ubuntu / Win7 / OpenVMS
Posts: 438

Rep: Reputation: 57
Quote:
Originally Posted by ashok.g View Post
Actually I don't have any DBD::Oracle driver installed on my PC.
But I had it on my remote machine.Is that the problem?
It does need to be on the machine running the Perl script. I'm actually surprised your program even executes without having the correct driver.

When I tried this, I actually got an error instead:
Code:
install_driver(Oracle) failed: Can't locate DBD/Oracle.pm in @INC (@INC contains: /usr/local/lib/perl5/5.8.9/BSDPAN /usr/local/lib/perl5/site_perl/5.8.9/mach /usr/local/lib/perl5/site_perl/5.8.9 /usr/local/lib/perl5/5.8.9/mach /usr/local/lib/perl5/5.8.9 .) at (eval 8) line 3.
Perhaps the DBD::Oracle perl module hasn't been fully installed,
or perhaps the capitalisation of 'Oracle' isn't right.
Available drivers: DBM, ExampleP, File, Gofer, Proxy, SQLite, Sponge.
 
Old 01-29-2010, 03:47 AM   #5
ashok.g
Member
 
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Original Poster
Rep: Reputation: 32
Quote:
Originally Posted by MBybee View Post
It does need to be on the machine running the Perl script. I'm actually surprised your program even executes without having the correct driver.
I think one should have driver installed on that machine if you want to connect to that driver.

Don't worry I am not able to compile the code without the driver installed on my machine....
 
  


Reply

Tags
database, oracle, remote


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting to IBM AS400 db2 database from perl keysorsoze Programming 2 10-12-2008 11:01 AM
LXer: Oracle(R) Database Standard Edition One and Oracle Enterprise Linux on HP Set New World Record for Price Performance with TPC-C Benchmark LXer Syndicated Linux News 0 06-12-2007 05:01 PM
Difference between Oracle Server and Oracle Database ganninu Programming 3 02-27-2007 01:06 AM
connecting to MYSQL remote database opsraja Linux - Software 1 02-18-2005 05:52 AM
Connecting Mysql Database on remote server akamol Programming 4 10-16-2003 11:46 AM


All times are GMT -5. The time now is 08:43 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration