6.6 Viewing Connection Strings Using the connstr Utility
You can run the Oracle Database Connection String command-line utility (connstr
) to display Oracle Database connect strings for all the available network service names.
You can use these strings in a client application or tool (such as SQL*Plus, Python, or JDBC Thin) to quickly connect to Oracle Database, or write these service name entries to the
tnsnames.ora
file for use with the local naming method.
The
connstr
script is included in a default installation. The utility displays connect strings for a single Oracle software installation, based on the available system configuration.
Note:
This utility is suitable for single-instance or Oracle Database Free installations but not for more complex configurations, such as Oracle Real Application Clusters (Oracle RAC) or Oracle Data Guard. It relies on the Listener Control utility (lsnrctl
), and thus you must run this utility on a computer hosting your Oracle Database and listener. However, you can use the displayed connect strings on any supported client system.
Example 6-1 Sample connstr Utility Output in the Easy Connect Format
Using Listener: LISTENER with Oracle Home: /app/oracle/product/23ai/dbhome_1 Service Name: sales.us.example.com Connection String: sales-server:1521/sales.us.example.com Connection strings can be used to connect to the specified service name. For SQL*Plus you can use: SQL> connect username@sales-server:1522/sales.us.example.com For Python you can use: connection = cx_Oracle.connect(user="username", password="password", dsn="sales-server:1521/sales.us.example.com") For JDBC Thin you can use: OracleDataSource ods = new OracleDataSource(); ods.setURL("jdbc:oracle:thin:@sales-server:1521/sales.us.example.com"); ods.setUser("username"); ods.setPassword("password"); Connection conn = ods.getConnection(); Write connect strings to tnsnames.ora (Y/N)? (Default: N): y
Related Topics
Parent topic: Quick Start to Oracle Net Services