Perl Oracle connection error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl Oracle connection error
# 1  
Old 01-11-2012
Java Perl Oracle connection error

I've a Centralized Server which can connect to all Oracle Databases.

When I was trying the below code it doesn't work, But tnsping was working fine.
Code:
#!D:/perl5/bin/perl.exe

use DBI;

my $dbh = DBI->connect('dbi:Oracle:QBDIWCE', 'IDUSER', 'SECRET123#' ) || die( $DBI::errstr . "\n" ) ;

my $sth = $dbh->prepare( "SELECT username FROM dba_users;" );

$sth->execute( );

exit;

Error as follows
Code:
D:\SharedData\EDM>perl Oracle_connect_test.pl
DBI connect('QBDIWCE','IDUSER',...) failed: ORA-12154: TNS:could not resolve the connect identifier specified
(DBD ERROR: OCIServerAttach) at Oracle_connect_test.pl line 14

when I searched in Google it felt that the above Connect is to connect only to the DB which is n the same server. So my question what is the code to connect to all other DB from a Centralized server.

Thanks
Gopal

Last edited by Scott; 01-11-2012 at 02:40 PM.. Reason: Please use code tags
# 2  
Old 01-11-2012
Quote:
The connection string is always of the form: "dbi:Oracle:<db identifier>" There are several ways to identify a database:
  1. If the database is local, specifying the SID or service name will be enough.
  2. If the database is defined in a TNSNAMES.ORA file, you can use the service name given in the file
  3. To connect without TNSNAMES.ORA file, you can use an EZCONNECT url, of the form: //host[port][/service_name]
Try with:

Code:
"dbi:Oracle:host=<dbhost>;sid=<oracle_sid>;port=<port>" ..

Or just define an alias in your tnsnames.ora.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Oracle Database connection from UNIX

Hi I have a question regarding Oracle connection using the below code ${ORACLE_HOME}/bin/sqlplus -s $user/$pwd@$sid <<!EOF 1>> $v_log_dir/$v_job_log.out 2>> $v_log_dir/$v_job_log.err / prompt stored procedure beginning . . . exec xx_interface_pkg.pr_xx_clms_out($datayears,$keepmonths); ... (3 Replies)
Discussion started by: smilingraja
3 Replies

2. Programming

Help in pro*c for Oracle connection

hi, am making oracle connection through pro*c using the following command sample: exec sql connect username identified by password. but m getting the following errors frequently even though listener and db is running fine but some times code is working fine and not giving errors. ... (2 Replies)
Discussion started by: senkerth
2 Replies

3. UNIX for Dummies Questions & Answers

Error Handling using ISQL for oracle connection in Perl

Hi Am making connection to oracle using ISQL as shown in the code. This code is just a minor part of a big code. I want to capture the error if the password/login is wrong or if connection is not made. I need to capture the error code also. Also, If such an error occurs, i need to exit out... (4 Replies)
Discussion started by: irudayaraj
4 Replies

4. Shell Programming and Scripting

Oracle connection with UBUNTU

Hi all, Will I be able to connect to oracle using UBUNTU. If so, can any one provide me the steps. I want to try table archival and sql loader using control files. Please do help. Thanks, Raaga (1 Reply)
Discussion started by: Raaga
1 Replies

5. Shell Programming and Scripting

SSH Connection To Oracle

My problem is this....:eek: Platform=Sun Solaris UNIX / Oracle 10g 1) I'm trying to SSH from my local system A to remote system B 2) Once connected, I need to sudo to ID that has the ability to connect to the Oracle database 3) Then run a script that connects via sqlplus and... (2 Replies)
Discussion started by: khand67
2 Replies

6. Shell Programming and Scripting

Perl connect to remote oracle db without local oracle installation

I want to use Perl to connect to a remote Oracle DB I have no oracle installation on my server (and dont plan on installing one) I am using solaris 9 on x86 server. Is this possible? I basically want to run some basic sql queries on the remote oracle db which I have access to using perl on my... (0 Replies)
Discussion started by: frustrated1
0 Replies

7. Shell Programming and Scripting

oracle connection from shell script

Hi, For connecting to oracle my script is using the command sqlplus username/password@db_instance_name.For this to work i am setting ORACLE_HOME,TNS_ADMIN and ORACLE_SID in a seperate script.My question is,could we make a connection to oracle just by the command sqlplus... (4 Replies)
Discussion started by: DILEEP410
4 Replies

8. Shell Programming and Scripting

Get two variables from oracle in a single connection

Hi all In my script i am getting two variables year and month from oracle by making two connections. In the first connection i am getting varaibel year and again i am making another connection and getting month variable from oracle. Is there any way i can get two field values from oracle and... (1 Reply)
Discussion started by: vasuarjula
1 Replies

9. Windows & DOS: Issues & Discussions

Oracle 9i ODBC connection

I am attempting to access an Oracle 9i database located on a Solaris server from an XP client. The server is running Oracle 9i9.2.0.1.0 and the XP is Oracle client 9i 9.2.0.1.0. When I start a listener on the server, the listener starts but I receive a message “The listener supports no services”. I... (3 Replies)
Discussion started by: jkuchar747
3 Replies

10. UNIX for Advanced & Expert Users

Unix + oracle connection

Requirements: Using a shell script I have to check the 4 values from a table in Oracle and then store the result as "Y" in a Unix variable if the values are desired and "N" if the values are not desired. Explanation: There is a table abc in oracle which has 4 fields. if all the four values... (2 Replies)
Discussion started by: decci_7
2 Replies
Login or Register to Ask a Question