配置ORACLE 11g绿色版客户端和PLSQL远程连接环境 ORA-12154错误

ORA-12154是比较常见的数据库连接错误,多发生在以下情况:

1、服务器的TNS监听问题

Linster.ora 文件可以备份一下删除,然后先起监听,再起数据库,10g可以自动注册上去.

Listener 和 Tnsname中也许有其他隐性字符,删除后用netca或netmgr重配,其中的Host尽量用本机IP地址配置.

2、找不到tnsnames.ora文件或者其他环境变量的问题


如果找不到这个文件,PL/SQL dev不会给出明显的错误提示,最好是先tnsping一下目标,然后再检查以下的环境变量是否设置正确:

(打开环境变量配置界面操作:我的电脑---属性---高级---环境变量,在系统变量部分新建或编辑即可。win7即以上操作系统为:计算机——属性——高级系统设置——环境变量)

为了避免不必要的麻烦,oracle的各种目录最好不要有圆括号和空格

1) 变量名:ORACLE_HOME(远程连接可省略)

  变量值:D:\noSpaceCharacter\instantclient_11_2
 
2) 变量名:TNS_ADMIN
  变量值:D:\noSpaceCharacter\instantclient_11_2
 
3) 变量名:NLS_LANG
  变量值:SIMPLIFIED CHINESE_CHINA.ZHS16GBK
  说明:该值定义所连接的数据库使用的编码,其它类型可自己到服务器看一下或网上查找一下。
4) 修改Path变量,在后面添加 D:\noSpaceCharacter\instantclient_11_2

3、tnsnames.ora文件格式错误

首先,确定字符编码是ANSI很重要

示例如下:

MYDB_192.168.1.88=(
    DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.88)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = orcl)
    )
)

最后附加一下相关的格式:

# This file contains the syntax information for 
# the entries to be put in any tnsnames.ora file
# The entries in this file are need based. 
# There are no defaults for entries in this file
# that Sqlnet/Net3 use that need to be overridden 
#
# Typically you could have two tnsnames.ora files
# in the system, one that is set for the entire system
# and is called the system tnsnames.ora file, and a
# second file that is used by each user locally so that
# he can override the definitions dictated by the system
# tnsnames.ora file.

# The entries in tnsnames.ora are an alternative to using
# the names server with the onames adapter.
# They are a collection of aliases for the addresses that 
# the listener(s) is(are) listening for a database or 
# several databases.

# The following is the general syntax for any entry in 
# a tnsnames.ora file. There could be several such entries 
# tailored to the user's needs.

= [ (DESCRIPTION_LIST =  # Optional depending on whether u have 
				# one or more descriptions
				# If there is just one description, unnecessary ]
	  (DESCRIPTION=
	    [ (SDU=2048) ]	# Optional, defaults to 2048
				# Can take values between 512 and 32K
	    [ (ADDRESS_LIST=    # Optional depending on whether u have
				# one or more addresses
				# If there is just one address, unnecessary ]
	      (ADDRESS=
		[ (COMMUNITY=) ] 
		(PROTOCOL=tcp)
		(HOST=)
		(PORT=)
	      )
	      [ (ADDRESS=
		  (PROTOCOL=ipc)
		  (KEY=)	
		)
	      ]
	      [ (ADDRESS=
		  [ (COMMUNITY=) ]
		  (PROTOCOL=decnet)
		  (NODE=)
		  (OBJECT=)
		)
	      ]
              ... # More addresses
	    [ ) ] # Optional depending on whether ADDRESS_LIST is used or not 
	    [ (CONNECT_DATA=
		(SID=)
		[ (GLOBAL_NAME=) ]
	      )
	    ]
	    [ (SOURCE_ROUTE=yes) ]  
	  )
	  (DESCRIPTION=     
	    [ (SDU=2048) ]	# Optional, defaults to 2048
				# Can take values between 512 and 32K
	    [ (ADDRESS_LIST= ]	# Optional depending on whether u have more
				# than one address or not
				# If there is just one address, unnecessary
	      (ADDRESS
		[ (COMMUNITY=) ]
		(PROTOCOL=tcp)
		(HOST=)
		(PORT=)
	      )
	      [ (ADDRESS=
		  (PROTOCOL=ipc)
		  (KEY=)
	         )
	      ]
	      ... 		# More addresses
	    [ ) ] 		# Optional depending on whether ADDRESS_LIST  
				# is being used
	    [ (CONNECT_DATA=
		(SID=)
		[ (GLOBAL_NAME=) ]
	      )
	    ]
	    [ (SOURCE_ROUTE=yes) ]
	  )
	  [ (CONNECT_DATA=
	      (SID=)
	      [ (GLOBAL_NAME=) ]
	    )
	  ]
	  ...   # More descriptions 
	[ ) ]	# Optional depending on whether DESCRIPTION_LIST is used or not

最后引用一下关于oracle PL/SQL绿色版在这个错误上的一些安装和配置说明:http://www.cnblogs.com/tearer/archive/2012/12/13/2815595.html

特别引用:Instant client的版本很多:主要是Basic和Basic Lite。 Basic版本包括了所有的支持运行OCI、OCCI、JDBC、JDBC-OCI的文件,支持多种语言。 Basic Lite是Basic版本的精简版,只包括了英文的错误描述,也只支持Unicode、ASCII和欧洲字符集。 因此,如果数据库服务器是中文字符集(如 SIMPLIFIED CHINESE_CHINA.ZHS16GBK),则必须下载Basic版本。

你可能感兴趣的:(数据库异常)