天天看點

【EZCONNECT】 sqlnet.ora檔案中EZCONNECT參數與Easy Connect Naming Method方法

如果對tnsnames.ora檔案沒有做充分的配置,也可以使用Oracle的Easy Connect Naming Method方法測試資料庫是否可以通路。

這裡不對這種方法的原理和詳細用法展開描述,這方面的資訊可以通過以下Oracle連接配接獲得。

http://download.oracle.com/docs/cd/B19306_01/network.102/b14212/naming.htm#i498306

或直接通路下屬文章進行參考。

Net Services Administrator's Guide - 2 Quick Start to Oracle Net Connections - Task 3: Configure the Client for Connection to a Database

Net Services Administrator's Guide - 8 Configuring Naming Methods - Using the Easy Connect Naming Method

簡單列一下該方法的使用文法,供參考。

CONNECT username/password@host[:port][/service_name][/instance_name]

CONNECT username/password@[//]host[:port][/service_name]

本文想要強調指出的是,如果想要使用Easy Connect Naming Method方法測試資料庫的連通性,需要在sqlnet.ora檔案中增加“NAMES.DIRECTORY_PATH= (EZCONNECT)”資訊,否則該功能将無法使用。

1.sqlnet.ora檔案的位置

該檔案與listener.ora和tnsnames.ora檔案處于同一目錄,具體目錄為:$ORACLE_HOME/network/admin。

2.體驗報錯,以此為鑒

如果是Windows用戶端沒有配置相應的參數,會收到如下報錯:

C:\Users\secooler>sqlplus sec/[email protected]:1521/ora10g

SQL*Plus: Release 10.2.0.3.0 - Production on 星期一 8月 2 21:19:01 2010

Copyright (c) 1982, 2006, Oracle.  All Rights Reserved.

ERROR:

ORA-12154: TNS: 無法解析指定的連接配接辨別符

請輸入使用者名:

ORA-12560: TNS: 協定擴充卡錯誤

SP2-0157: 在 3 次嘗試之後無法連接配接到 ORACLE, 退出 SQL*Plus

C:\Users\secooler>

如Linux伺服器端的sqlnet.ora檔案沒有設定相應的參數,将會收到如下錯誤:

sec@secdb /home/oracle$ sqlplus sec/[email protected]:1521/ora10g

SQL*Plus: Release 10.2.0.3.0 - Production on Mon Aug 2 21:21:34 2010

ORA-12154: TNS:could not resolve the connect identifier specified

Enter user-name:

ORA-01017: invalid username/password; logon denied

SP2-0157: unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus

兩種錯誤内容是一樣的,從錯誤提示上看,很難直接定位是由于sqlnet.ora檔案配置問題導緻的。這就需要我們對Easy Connect Naming Method的原理深入了解。

3.向sqlnet.ora檔案中添加“EZCONNECT”資訊,解決該問題

“EZCONNECT”這個單詞很好了解,從發音上即可等同于“Easy Connect”。從此,該參數将不再陌生。

sec@secdb /home/oracle$ cat $ORACLE_HOME/network/admin/sqlnet.ora

# sqlnet.ora Network Configuration File: /oracle/app/oracle/product/10.2.0/db_1/network/admin/sqlnet.ora

# Generated by Oracle configuration tools.

NAMES.DIRECTORY_PATH= (TNSNAMES,EZCONNECT)

在添加完參數後嘗試連接配接,成功。

sec@secdb /oracle$ sqlplus sec/[email protected]:1521/ora10g

SQL*Plus: Release 10.2.0.3.0 - Production on Mon Aug 2 21:31:50 2010

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production

With the Partitioning, Oracle Label Security, OLAP and Data Mining Scoring Engine options

sec@ora10g>

4.小結

Oracle提供了很多類似文中提到的Easy Connect Naming Method小技巧。建議在使用這些便捷方法之前充分了解工具使用的前提和限制,這樣可以在提高效率的同時不至于帶來太多的障礙。

Good luck.

secooler

10.08.02

-- The End --