Erlang在Redhat 5.3下使用unixODBC连接Oracle数据库的配置
来源:互联网 发布:java sql注入拦截器 编辑:程序博客网 时间:2024/05/16 08:49
个人在安装配置时遇到一些麻烦,特此记录如下:
- 环境
数据库服务器操作系统:Windows 2003
数据库:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0erlang运行的服务器操作系统:Redhat 5.3
erlang:Erlang R14B03 (erts-5.8.4)
- 注意
redhat 5.3中默认安装的unixODBC是2.2.11版本,这个版本与oracle的odbc驱动不兼容。所以需要将先将其卸载,然后安装unixODBC 2.3.0
卸载unixODBC的rpm包:
rpm -e mysql-connector-odbc-3.51.12-2.2.i386
rpm -e unixODBC-devel-2.2.11-7.1
rpm -e unixODBC-2.2.11-7.1
下载安装unixODBC 2.3.0
从www.unixodbc.org处下载,或者
http://olex.openlogic.com/package_versions/download/10003?package_version_id=5966&path=openlogic%2Funixodbc%2F2.3.0%2Fopenlogic-unixodbc-2.3.0-all-src-2.zip
在configure时加两个参数:--sysconfdir=/etc --prefix=/usr
然后make install就可以啦
安装完成后执行odbcinst -j可以看到配置文件等的位置
===============================================================================
1. 从Oracle网站下载客户端安装包
http://download.oracle.com/otn/linux/instantclient/11203/oracle-instantclient11.2-basic-11.2.0.3.0-1.i386.rpm
http://download.oracle.com/otn/linux/instantclient/11203/oracle-instantclient11.2-odbc-11.2.0.3.0-1.i386.rpm
最好再安装一下sqlplus
http://download.oracle.com/otn/linux/instantclient/11203/oracle-instantclient11.2-sqlplus-11.2.0.3.0-1.i386.rpm
2. 配置lib目录
cd /usr/lib/oracle/11.2/client/lib
pwd >>/etc/ld.so.conf
ldconfig
3. 修改/etc/odbcinst.ini
增加如下:
# Driver form oracle
[Oracle]
Desription = ODBC for Oracle
Driver = /usr/lib/oracle/11.2/client/lib/libsqora.so.11.1
Setup = /usr/lib/liboraodbcS.so
FileUsage = 1
这个加到odbcinst.ini文件的最后。测试时用,正常使用时应该去掉
[ODBC]
Trace = 1
TraceFile =/tmp/odbc.log
Debug = 1
Pooling = No
4. 修改/etc/odbc.ini
增加如下
[ORCL_146] #本地数据源名
Description = ODBC for Oracle
Driver = Oracle
Server = 192.168.1.146
Port = 1521
ServerName = ORCL_146 #tnsnames.ora中的服务名
UserID = mycomm
Password = mycomm123
5. 增加/usr/lib/oracle/11.2/network/admin/tnsnames.ora
ORCL_146 =(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.146)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl)
)
)
其中ORCL_146要与odbc.ini的ServerName相同,
SERVICE_NAME为oracle的服务名
HOST为数据库所在主机IP,PORT为数据库所在主机port。
6. 在/etc/profile中增加:
export TNS_ADMIN=/usr/lib/oracle/11.2/network/admin/
然后,为了让TNS_ADMIN环境变化现在就生效,执行
. /etc/profile
7. 用isql测试一下
isql ORCL_146 -v
出错:
[01000][unixODBC][Driver Manager]Can't open lib '/usr/lib/oracle/11.2/client/lib/libsqora.so.11.1' : libclntsh.so.11.1: cannot open shared object file: No such file or directory
[ISQL]ERROR: Could not SQLConnect
发现是没有libclntsh.so.11.1这个库文件,这个库文件在/usr/lib/oracle/11.2/client/lib/下,之所以没有找到是由于在第2步时执行ldconfig的终端不是现在执行isql的终端。
重新执行一下ldconfig
再执行isql ORCL_146 -v
出错:
isql: symbol lookup error: /usr/lib/oracle/11.2/client/lib/libsqora.so.11.1: undefined symbol: SQLGetPrivateProfileStringW
这个问题就是unixODBC的版本问题啦,如果前面安装了unixODBC 2.3.0的话不会出现这个错误
如果sqlplus可以连接,但isql不可以,需要确认是否export了TNS_ADMIN这一环境变量
8. erlang odbc 连接oralce时出错如下:
------------------------------------------
Erlang R14B03 (erts-5.8.4) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.8.4 (abort with ^G)
1> odbc:start().
ok
2> odbc:connect("DSN=ORCL_146;UID=scott;PWD=tiger", []).
=ERROR REPORT==== 21-Oct-2011::19:23:49 ===
ODBC: received unexpected info: {tcp_closed,#Port<0.725>}
{error,connection_closed}
3>
=ERROR REPORT==== 21-Oct-2011::19:23:49 ===
** Generic server <0.39.0> terminating
** Last message in was {#Port<0.723>,{exit_status,23}}
** When Server state == {state,#Port<0.723>,
{<0.32.0>,#Ref<0.0.0.38>},
<0.32.0>,undefined,on,undefined,undefined,on,
connecting,undefined,0,
[#Port<0.721>,#Port<0.722>],
#Port<0.724>,#Port<0.725>}
** Reason for termination ==
** {port_exit,collecting_of_driver_information_faild}
----------------------------------------------
根据这里的方法
http://www1.erlang.org/pipermail/erlang-questions/2005-August/016816.html
这样连接就可以啦
3> odbc:connect("DSN=ORCL_146;UID=scott;PWD=tiger", [{scrollable_cursors, off}]).
{ok,<0.41.0>}
4>
其实这里可以不用UID和PWD,只要一个DSN就可以啦,形如:
odbc:connect("DSN=ORCL_146", [{scrollable_cursors, off}]).
- Erlang在Redhat 5.3下使用unixODBC连接Oracle数据库的配置
- Linux下用unixODBC连接Oracle数据库的配置
- 使用unixodbc连接 ORACLE数据库的配置方法
- Linux使用unixODBC连接到Oracle数据库
- 在Linux下使用perl通过unixODBC连接SQLServer2000
- !!redhat配置freetds和unixodbc的方法
- !!redhat配置freetds和unixodbc的方法
- linux下oracle通过unixODBC连接MySQL
- RHEL5下unixODBC 与 sqliteodbc 连接配置
- unixodbc 连接mysql数据库
- unixodbc 连接mysql数据库
- 使用PHP5 通过unixODBC/easysoft oracle odbc driver 连接 ORACLE
- ubuntu下通过unixodbc和freetds连接数据库
- 在Tomcat下配置连接池(oracle数据库)
- 在Ubuntu 10.04中文版下Qt编程,使用unixODBC和FreeTDS连接MS SQL Server 2005,并且中文不出现乱码的方法
- 在Ubuntu 10.04中文版下Qt编程,使用unixODBC和FreeTDS连接MS SQL Server 2005,并且中文不出现乱码的方法
- 在Ubuntu 10.04中文版下Qt编程,使用unixODBC和FreeTDS连接MS SQL Server 2005,并且中文不出现乱码的方法
- C通过unixODBC连接数据库
- c/c++遇到的一个问题
- java用户角色权限设计
- pkg-config
- Subversion 不能识别 svn协议访问
- VC常用数据类型使用转换详解
- Erlang在Redhat 5.3下使用unixODBC连接Oracle数据库的配置
- 19. 5. 3. URLConnection常用方法 Header Viewer
- 推广景城网过程中积累的高全中博客资源,和大家分享一下
- 用万用表检测PC电源故障方法
- 数据挖掘数据集资源
- 含头的CheckBox列表的使用实例
- H.264视频的RTP荷载格式
- linux command 小记
- [转载]COleDateTime类型的应用