最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

Erlang在Redhat5.3下使用unixODBC连接Oracle数据库的配置

来源:动视网 责编:小采 时间:2020-11-09 07:28:00
文档

Erlang在Redhat5.3下使用unixODBC连接Oracle数据库的配置

Erlang在Redhat5.3下使用unixODBC连接Oracle数据库的配置:个人在安装配置时遇到一些麻烦,特此记录如下: 环境 数据库服务器操作系统:Windows 2003 数据库:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 erlang运行的服务器操作系统:Redhat 5.3 erlang:Erlang R14B0
推荐度:
导读Erlang在Redhat5.3下使用unixODBC连接Oracle数据库的配置:个人在安装配置时遇到一些麻烦,特此记录如下: 环境 数据库服务器操作系统:Windows 2003 数据库:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 erlang运行的服务器操作系统:Redhat 5.3 erlang:Erlang R14B0


个人在安装配置时遇到一些麻烦,特此记录如下: 环境 数据库服务器操作系统:Windows 2003 数据库:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 erlang运行的服务器操作系统:Redhat 5.3 erlang:Erlang R14B03 (erts-5.8.4) 注意 ==========

个人在安装配置时遇到一些麻烦,特此记录如下:

  • 环境
  • 数据库服务器操作系统:Windows 2003

    数据库:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0

    erlang运行的服务器操作系统: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在Redhat5.3下使用unixODBC连接Oracle数据库的配置

    Erlang在Redhat5.3下使用unixODBC连接Oracle数据库的配置:个人在安装配置时遇到一些麻烦,特此记录如下: 环境 数据库服务器操作系统:Windows 2003 数据库:Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 erlang运行的服务器操作系统:Redhat 5.3 erlang:Erlang R14B0
    推荐度:
    标签: 使用 数据库 配置
    • 热门焦点

    最新推荐

    猜你喜欢

    热门推荐

    专题
    Top