官术网_书友最值得收藏!

Local database connections

Establishing a connection locally means running the SQL command-line utility on the same computer where Oracle Database 11g XE is installed, and initiating a database connection command using the valid database credentials.

The following screenshot is taken from Oracle Database 11g XE on Windows, and demonstrates establishing a local database connection to the database:

Local database connections

Navigate to the Oracle Database 11g XE database home and start the sqlplus session with the /nolog option. Using the connect statement establish a connection to the database by supplying the valid database username and password. As shown in the preceding screenshot, connect as SYSTEM user with the password entered while installing Oracle Database 11g XE.

ORA_DBA is a local Windows group that gets automatically created when you install Oracle Database XE and your Windows username automatically gets added to this group. Members of ORA_DBA can connect to the Oracle Database XE without a password, as shown in the following screenshot:

Local database connections

Oracle Net Listener

To connect to the database remotely, we should have Oracle Net Listener running on the host where Oracle Database 11g XE is installed. When a remote client initiates a database connection request, this connection request is received by Oracle Net Listener. The job of the listener is to listen to these incoming database connection requests and hand over the connection requests to the appropriate databases.

Thereafter the remote-client connection directly communicates with the database without the need of the listener. Without the listener service running we cannot connect to the database remotely. There may be more than one database running on the host server; however, you will only have one database listener for all incoming requests. Based on the incoming request, Oracle Net Listener will hand over the connection request to the appropriate database.

Oracle Net Listener and the tnsnames.ora files are configured by default when we install Oracle Database 11g XE. The listener's configuration file is located under $ORACLE_HOME\network\admin\listener.ora. Oracle Database XE automatically creates a Windows service for Oracle Net Listener (OracleXETNSListener).

Configuring Oracle Net Listener

listener.ora is the name of the Oracle Net Listener configuration file and it resides under $ORACLE_HOME\network\admin.

The content of a sample listener.ora file in its simplest form is as follows:

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = XE)
(ORACLE_HOME = C:\oraclexe\app\oracle\product\11.2.0\server)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = amomen-PC)(PORT = 1521))
)
)

The description of the parameters is as follows:

  • LISTENER: The name of the listener
  • SID_NAME: The Oracle Database name
  • ORACLE_HOME: The Oracle software installation home directory
  • HOST: The name of the host where Oracle Net Listener is running
  • PORT: The port on which Oracle Net Listener is listening to the incoming requests

Make the necessary changes to the preceding parameters, save the file, and restart the Windows Oracle Listener service OracleXETNSListener.

Viewing the status of Oracle Net Listener

Navigate to Oracle home ($ORACLE_HOME\bin), start the listener utility (lsnrctl), enter status as shown in the following screenshot, and hit Enter.

If the listener is not started, the command displays an error message, as shown in the following screenshot:

Viewing the status of Oracle Net Listener

If the listener is running, the command displays detailed listener information as shown in the following screenshot:

Viewing the status of Oracle Net Listener

Starting and stopping the listener

The listener is automatically configured when we install Oracle Database 11g XE.

  • To stop the listener on Windows, launch the Services window by navigating to Start | Control Panel | Administrative Tools | Services and stop the OracleXETNSListener service, or launch the listener utility (lsnrctl) and enter the LSNRCTL> stop command. To stop the listener on Linux, within the listener utility (lsnrctl) enter the stop command as we did in the Windows environment.
  • To start the listener on Windows, launch the Services window by navigating to Start | Control Panel | Administrative Tools | Services and start the OracleXETNSListener service, or launch the listener utility (lsnrctl) and enter the LSNRCTL> start command. To start the listener on Linux, within the listener utility (lsnrctl) enter the start command as we did in Windows environment.

Configuring the tnsnames.ora file

Transparent Network Susbstrate (TNS) handles all remote database connections. Oracle software reads the TNS connection string to understand how to connect to the remote databases. Every Oracle database and the Oracle Client software will have this file. By default the tnsnames.ora file is located under $ORACLE_HOME\network\admin. A sample alias entry from the tnsnames.ora file is as follows:

MY_XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = amomen-PC)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SID = XE)
)
)

In the preceding code:

  • MY_XE is an alias name. You can name it anything you like.
  • HOST is the hostname or IP-Address where database is running.
  • PORT is the port number on which Oracle Net Listener is listening.
  • SID is the Oracle database name.

When connecting to the remote database, we will use my_xe as a connect string.

主站蜘蛛池模板: 宁明县| 陇川县| 天祝| 佛坪县| 灵武市| 宝兴县| 南漳县| 浦东新区| 邓州市| 庆元县| 开鲁县| 和田县| 堆龙德庆县| 开鲁县| 汉川市| 渭南市| 娄烦县| 平江县| 平顶山市| 绥棱县| 惠州市| 屯门区| 温州市| 镇远县| 嘉兴市| 辰溪县| 尚义县| 聊城市| 南投县| 荆门市| 林州市| 安福县| 新丰县| 宁远县| 娄底市| 双峰县| 民县| 海安县| 开化县| 南安市| 天长市|