不安装Oracle客户端连接数据库的方法
本机环境: win7 64位中文旗舰版
一、准备工作:
1)到ORACLE官网下载instantclient,下载地址:http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html ,注意下载对应版本的,(主要要和PL/SQL或者TOAD的版本要对应)
解压缩到 D:\instantclient-basic-nt-12.2.0.1.0下
2)将ORACLE服务端C:\app\Administrator\product\11.2.0\dbhome_1中的NETWORK拷贝到该目录下,或者自己新建目录\NETWORK\ADMIN,
将实际需要使用的tnsnames.ora和sqlnet.ora两个配置文件拷贝到network/admin目录下
3)系统变量中设置:(也可以写入注册表)
本机 "控制面板"-"系统"-"高级"-"环境变量"-"系统变量"添加
在Path变量后加入)
;D:\instantclient-basic-nt-12.2.0.1.0\instantclient_12_2
新建系统变量:
LD_LIBRARY_PATH(该变量可能可以省略) = D:\instantclient-basic-nt-12.2.0.1.0\instantclient_12_2
NLS_LANG = SIMPLIFIED CHINESE_CHINA.ZHS16GBK(注意空格,这是设置语言,可以根据情况配置)
LANG = zh_CN.GBK
ORACLE_HOME=D:\instantclient-basic-nt-12.2.0.1.0\instantclient_12_2
SQL_PATH = D:\instantclient-basic-nt-12.2.0.1.0\instantclient_12_2
TNS_ADMIN = D:\instantclient-basic-nt-12.2.0.1.0\instantclient_12_2
二、使用 PL/SQL Developer
1、安装 PL/SQL Developer 软件
2、双击运行出现登录界面 => cancel => Tools => Preferences => 首页也即Connection界面设置两个变量
Oracle home =>D:\instantclient-basic-nt-12.2.0.1.0\instantclient_12_2\network
OCILibrary => D:\instantclient-basic-nt-12.2.0.1.0\instantclient_12_2\oci.dll
3、测试 Session => LogOn => 比如以 scott身份登录,输入口令 oracle,选择 orcl, connect as normal 登录
File => New => SQL Window =>
在SQL 里输入 select * from emp; 然后点击左上角 那个* 或着直接按 F8
在SQL语句下面会出现 结果集 列表 OK,宣告成功
三、使用 Toad
1 安装 Toad 11
初始设置俺一路 NEXT 过
2 右键以管理员身份运行
3 测试,在出现的界面右方
User / Schema: sys
Password: oracle
TNS => Database: orcl
Connect as: SysDBA
Connect Using: 会自动出现 instantclient_12_2
如果不自动出现则肯定哪里配置的不对,比如监听设置错误
点击conect即可登录
四、遇到的问题
根据出错信息判断出客户端未监听到实例服务名
1、通过重启服务的方式启动数据库,再次连接仍无法连接服务器。
2、既然第一种方法不能解决问题,那就第二种方法。考虑监听listener.ora
2.1 检查服务端listener.ora文件
C:\app\Administrator\product\11.2.0\dbhome_1\NETWORK\ADMIN\listener.ora
发现无红色字体那一段话,加上并且重启
# listener.ora Network Configuration File: C:\app\Administrator\product\11.2.0\dbhome_1\network\admin\listener.ora
# Generated by Oracle configuration tools.
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = CLRExtProc)
(ORACLE_HOME = C:\app\Administrator\product\11.2.0\dbhome_1)
(PROGRAM = extproc)
(ENVS = "EXTPROC_DLLS=ONLY:C:\app\Administrator\product\11.2.0\dbhome_1\bin\oraclr11.dll")
)
(SID_DESC =
(GLOBAL_DBNAME = ORCL)
(ORACLE_HOME = C:\app\Administrator\product\11.2.0\dbhome_1)
(SID_NAME = ORCL)
)
)
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
)
ADR_BASE_LISTENER = C:\app\Administrator
2.2 也可能继续报错,此时需要检查D:\instantclient-basic-nt-12.2.0.1.0\instantclient_12_2
目录下是否有别的tnsnames.ora文件,如果有的话要删除或者配置改成正确的。
2.3 tnsnames.ora文件设置
# tnsnames.ora Network Configuration File: C:\app\Administrator\product\11.2.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)