Nesh has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks... I am trying to connect to a database without having the TNS entry for that database on my local machine. Till now I have been using
$dbh = DBI->connect ($dsn, $user, $password, {PrintError =>1,RaiseErro +r =>1})
But I was wondering that is there a way to simply feed the IP address and the port number alongwith the username and password to connect to the database. Thanks for all your help. Neshat
  • Comment on Database connection over a network without having a local TNS entry
  • Download Code

Replies are listed 'Best First'.
Re: Database connection over a network without having a local TNS entry
by davidrw (Prior) on Jun 18, 2005 at 01:36 UTC
    Yes -- you can specify the hostname and port in the DSN string. From DBI, it says that the dsn is dbi:DriverName:database=database_name;host=hostname;port=port

    Are you on oracle? What is your value for $dsn?
    The DBD::Oracle page has a section on "Connecting without environment variables or tnsname.ora file" that has the example (you can also use port= with it):
    $dbh = DBI->connect("dbi:Oracle:host=myhost.com;sid=ORCL", $user, $pa +sswd);
      Hi Thanks for the reply. I am using Oracle database. Suppose database host is neshat; port is 1521 and database name is abcd. I did it as
      $dbh = DBI->connect("dbi:Oracle:database=abcd;host=neshat;port=1521", +$user, $password, {PrintError => 1, RaiseError => 1}) or die "Can't e +xecute statement: $DBI::errstr";
      Still it gives me error. Where am I wrong? Thanks for your help.
        So what's the (exact) error message?

        What about the obivous questions of correct user/password values and firewall issues?
Re: Database connection over a network without having a local TNS entry
by Ovid (Cardinal) on Jun 18, 2005 at 01:41 UTC