1 Reply Latest reply on Jun 29, 2006 6:58 PM by 392393

    Errors connecting to Oracle via perl DBI

    520855
      Hi List.

      I've installed Oracle on my linux box (SuSE 10) and I've installed
      DBD::Oracle.

      I can run sqlplus as the oracle user however when I try and connect via
      DBD::Oracle in a perl script I always get errors as follows:

      connect string =
      my $dbh = DBI->connect("dbi:Oracle:ORCL", 'oracle', 'oracle' );

      error =
      DBI connect('ORCL','oracle',...) failed: ORA-12541: TNS:no listener (DBD
      ERROR: OCIServerAttach) at ora1.pl line 7
      Connection Failed...

      connect string =
      my $dbh = DBI->connect("dbi:Oracle:HOST=linux.site;SID=ORCL;PORT=1522",
      'oracle', 'oracle' );

      error =
      DBI connect('HOST=linux.site;SID=ORCL;PORT=1522','oracle',...) failed:
      ORA-12541: TNS:no listener (DBD ERROR: OCIServerAttach) at ora1.pl line 7
      Connection Failed...



      Maybe I have the connect string wrong?


      Below is a listing of my code, and my tnsnames.ora:
      Thanks in advance for your help.


      ############ code listing ################ #!/usr/bin/perl

      use DBI;

      print "Started\n";

      my $dbh = DBI->connect("dbi:Oracle:HOST=linux.site;SID=ORCL;PORT=1522",
      'oracle', 'oracle' );


      if ($dbh) {
      print "Connected...\n";
      }
      else {
      print "Connection Failed...\n";
      exit;
      }

      my $qry = $dbh->prepare("select count(*) from dba_tables");
      $qry->execute();

      my @data = $qry->fetchrow_array();

      print "[$data[0]] [$data[1]] [$data[2]]\n";


      exit;




      ######### tnsnames.ora listing #####################
      # Generated by Oracle configuration tools.

      LISTENER_ORCL =
      (ADDRESS = (PROTOCOL = TCP)(HOST = linux.site)(PORT = 1522))


      ORCL =
      (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = linux.site)(PORT = 1522))
      (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
      )
      )

      EXTPROC_CONNECTION_DATA =
      (DESCRIPTION =
      (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC2))
      )
      (CONNECT_DATA =
      (SID = PLSExtProc)
      (PRESENTATION = RO)
      )
      )