Database Reference
In-Depth Information
Connecting Through the TCP/IP Adapter
Use of the TPC/IP protocol enables clients to connect to a DBMS instance from any system
within a network. Following is an example of an Oracle Net service name definition for a TCP/
IP connection:
TEN_TCP.WORLD =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST=dbserver.oradbpro.com)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = TEN)
)
)
The listener needs to support the TCP/IP protocol too.
LISTENER =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = TEN))
(ADDRESS = (PROTOCOL = TCP)(HOST=dbserver.oradbpro.com)(PORT = 1521))
)
)
This is the Perl code to connect using the service name TEN_TCP.WORLD :
use DBI;
my $dbh = DBI->connect("DBI:Oracle:TEN_TCP.WORLD", "ndebes", "secret") or die
"Connect failed: $DBI::errstr";
As you can see, the Perl code is analogous to the IPC connection. Merely the Oracle Net
service name passed as part of $data_source has changed. All three arguments to connect can
be undef , if the corresponding environment variables DBI_DSN , DBI_USER , and DBI_PASS are set
using SET on Windows and export on UNIX.
my $dbh = DBI->connect(undef, undef, undef) or die "Connect failed: $DBI::errstr";
Two other approaches for connecting through the TCP/IP adapter without requiring Net
service name resolution by a naming method, such as Local Naming (tnsnames.ora) or LDAP
(Light Weight Directory Access Protocol), exist. The first has syntax similar to a Java JDBC URL
and specifies host, port, and ORACLE_SID as part of the data source $dsn . Here's an example:
my $dbh = DBI->connect("DBI:Oracle:host=dbserver.oradbpro.com;port=1521;sid=TEN",
"ndebes", "secret")
or die "Connect failed: $DBI::errstr";
The port number may be omitted. If it is, both 1521 and 1526 are tried. The sequence of the
fields host , port , and sid is irrelevant. Another method is to supply the full description that
would otherwise be retrieved from the configuration file tnsnames.ora in the argument $dsn .
 
Search WWH ::




Custom Search