DataStage 配置ODBC

1 配置ODBC需要了解的基础知识

配置ODBC的步骤:

  • 在.odbc.ini 文件里配置ODBC数据源信息
  • 在uvodbc.config文件里配置数据源名称信息(DSN)
  • 测试数据源

路径和文档信息:

名称说明
DataStage默认安装驱动的路径/opt/IBM/InformationServer/Server/branded_odbc
关于ODBC配置的文档/opt/IBM/InformationServer/Server/branded_odbc/docs
哪里配置ODBC信息$DSHOME/.odbc.ini
哪里配置ODBC data Source name(DSN)$DSHOME/uvodbc.config和每个DataStage项目下的uvodbc.config

1.1 说明

在$DSHOME/.odbc.ini内配置ODBC数据源信息,这里配置的信息包括驱动、服务器、用户、端口等信息,这个文件的名称和路径不是绝对的,可以在$DSHOME/dsenv 文件内的ODBCINI变量配置:

  ODBCINI=$DSHOME/.odbc.ini
  export ODBCINI

dsenv 是非常重要的配置文件,修改该文件必须重启Enginer生效,里面的变量信息对所有项目有效,并且可以在开发项目时引用。
在uvodbc.config文件里配置ODBC数据源名称(DSN),这里配置的信息和上面的.odbc.ini不一样,.odbc.ini文件是详细的数据源配置信息,而这里是配置DSN,可以理解为.odbc.ini里配置了数据源详细信息,而uvodbc.config文件是给项目提供的引用接口定义。

<Oracle_30>
DBMSTYPE = ODBC

Oracle_30表示数据源名称,名称必须和.odbc.ini里面配置的一样。
DBMSTYPE指定该数据源的类型。

2 Oracle 数据源配置

Oracle 数据源配置方式有两种:

  • 基于DWire Protocol Driver配置ODBC:这种方式不需要Oracle客户端软件,也不需要配置Oracle环境变量
  • 基于TNS配置ODBC:这种方式需要配置Oracle环境变量并且必须有$ORACLE_HOME/network/admin/tnsnames.ora TNS配置文件

2.1 基于DWire Protocol Driver配置ODBC

2.1.1 配置.odbc.ini

在$DSHOME/.odbc.ini文件中找到官方提供的预配置ODBC数据源[Oracle Wire Protocol],复制该段内容,修改ODBC配置信息.

[Oracle_30]
Driver=/opt/IBM/InformationServer/Server/branded_odbc/lib/VMora24.so
Description=DWire Protocol Driver for server 30
ApplicationUsingThreads=1
ArraySize=60000
CachedCursorLimit=32
CachedDescLimit=0
CatalogIncludesSynonyms=1
CatalogOptions=0
DefaultLongDataBuffLen=1024
DescribeAtPrepare=0
EnableDescribeParam=0
EnableNcharSupport=0
EnableScrollableCursors=1
EnableStaticCursorsForLongData=0
EnableTimestampWithTimeZone=0
HostName=127.0.0.1
LocalTimeZoneOffset=
LockTimeOut=-1
LogonID=
Password=
PortNumber=1521
ProcedureRetResults=0
SID=testdb
UseCurrentSchema=1

这里Oracle_30表示数据源名称,HostName表示数据库所在的主机名,PortNumber表示数据库端口,SID表示数据库实例ID;将内容保存到.odbc.ini文件中。

2.1.2 配置uvodbc.config

编辑$DSHOME/uvodbc.config文件,增加上面在.odbc.ini文件中配置的ODBC数据源信息。

[ODBC DATA SOURCES]

<localuv>
DBMSTYPE = UNIVERSE
network = TCP/IP
service = uvserver
host = 127.0.0.1

<Oracle_30>
DBMSTYPE = ODBC

DNS名称Oracle_30必须和.odbc.init中的一致。**注意:该文件在两个地方存在,一个在$DSHOME目录下,一个在项目的目录下,当创建新项目时,DataStage拷贝该文件到新项目目录下;DS项目运行时首先查找项目下的uvodbc.config文件,如果未找到则查找$DSHOME/uvodbc.config文件,所以编辑完成后要将该文件拷贝到项目目录下;当然这种方式只在多个项目需要访问相同的ODBC的情况下介意这么做,如果每个项目所使用的ODBC不同,那么最好的方式就是编辑项目目录下的uvodbc.config文件了。

2.1.3 测试ODBC数据源

进入DSHOME目录使用dssh工具测试数据源。

$ cd $DSHOME
$ ./dsenv
$ ./dssh
DataStage Command Language 8.5 Licensed Materials - Property of IBM
(c) Copyright IBM Corp. 1997, 2009 All Rights Reserved.
DSEngine logged on: Friday, September 25, 2015 09:07

键入LOGTO 项目名称进入项目,注意项目名称区分大小写。

>LOGTO dstest

键入DS_CONNECT命令查看该项目所有的ODBC源配置,这里你可以看到项目使用的uvodbc.config文件和刚才配置的Oracle_30数据源了。

>DS_CONNECT

Data Source information from /opt/IBM/dsprojects/dstest/uvodbc.config:

Data Source:       localuv
  DBMS Type:         UNIVERSE
  Network Type:      TCP/IP
  Host System:       loopback   127.0.0.1
  Service Name:      uvserver

Data Source:       Oracle_30
  DBMS Type:         ODBC

键入DS_CONNECT Oracle_30测试数据源,注意数据源名称区分大小写。根据提示输入数据库用户名和密码。

>DS_CONNECT Oracle_30
Enter username for connecting to 'Oracle_30' DBMS [dsadm]: dsource
Enter password for dsource: 

如果没有任何的报错,那说明数据源测试成功了,并且>提示变为了数据源名称>(Oracle_30>);你可以键入sql验证数据源。

Oracle_30> select * from tab;
     TNAME     TABTYPE   CLUSTERID  
----------  ----------  ----------  
    DOBJ01       TABLE        NULL  

1 row selected

2.2 基于TNS配置ODBC

2.2.1 什么时候使用TNS配置ODBC

  • 当GoldenGate服务器上存在Oracle服务端或客户端软件时
  • 当数据库地址端口经常发生变化时
  • 当多个应用程序和GoldenGate需要同时访问一个数据源时
  • 当GoldenGate所在的服务器不能直接连接数据库需要通过TNS代理连接时

这种方式需要配置Oracle环境变量,也必须有$ORACLE_HOME/network/admin/tnsnames.ora TNS配置文件,并且GoldenGate具有读取该文件的权限。

2.2.2 在dsenv文件中配置Oracle环境

$ cd $DSHOME
$ vi dsenv

export ORACLE_HOME=/opt/oracle/product/11.2.0
export LIBPATH=$LIBPATH:$ORACLE_HOME/lib:$ORACLE_HOME/rdbms/lib
export PATH=$PATH:$ORACLE_HOME/bin
export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_SID=testdb
export TNS_ADMIN=/opt/oracle/product/11.2.0/network/admin

配置完成后必须重启Engine使配置文件生效。

$ uv -admin -stop
$ uv -admin -start

注意:在重启Engine后,你要确认上面的变量是否在你当前会话环境中生效,否则会影响后面的测试,如果未生效可能是你的配置错误或者之前的配置与之冲突导致变量失效,请尝试重新登录会话确定。

2.2.3 在TNS文件中配置ServerName和其它信息

$ vi /opt/oracle/product/11.2.0/network/admin/tnsnames.ora

xmeta_111 =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = testhost)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = xmeta)
    )
  )

2.2.4 在.odbc.ini文件中配置数据源信息

[Ora_remote_111]
Driver=/software/IBM/InformationServer/Server/branded_odbc/lib/VMora24.so
Description=DataDirect Oracle for remote server 
ApplicationUsingThreads=1
ArraySize=60000
CachedCursorLimit=32
CachedDescLimit=0
CatalogIncludesSynonyms=1
CatalogOptions=0
DefaultLongDataBuffLen=1024
DescribeAtPrepare=0
EnableDescribeParam=0
EnableNcharSupport=0
EnableScrollableCursors=1
EnableStaticCursorsForLongData=0
EnableTimestampWithTimeZone=0
LocalTimeZoneOffset=
LockTimeOut=-1
LogonID=
Password=
ProcedureRetResults=0
ServerName=xmeta_111
UseCurrentSchema=1

这里不需要配置主机、端口信息,只需要配置ServerName为TNS文件中的serverName。

2.2.5 在uvodbc.config文件中配置数据源DSN

<Ora_remote_111>
DBMSTYPE = ODBC

这样就可以了,再通过2.1.3 中的那样测试ODBC数据源吧。

2.2.6 可能遇到的错误

>ds_connect Ora_remote_111
Enter username for connecting to 'Ora_remote_111' DBMS [dsadm]: scott
Enter password for scott: 
SQLConnect error:   Status = -1   SQLState = 08001   Natcode = -1
[ODBC] [IBM(DataDirect OEM)][ODBC Oracle Wire Protocol driver][Oracle]TNS-12505: TNS:listener could not resolve SID given in connect descriptor
Network connection to Data Source 'Ora_remote_111' failed

服务端不能识辨sid,这类错误有两种原因:

  • TNS文件中的SID或者Service_name配置错误,请尝试在sqlplus下测试该配置的可连接性,或者使用Easy connect name method方式测试连接
  • .odbc.init中的数据源信息配置错误,请检查ServerName的值是否配置正确
>ds_connect Ora_remote_111
Enter username for connecting to 'Ora_remote_111' DBMS [dsadm]: scott
Enter password for scott: 
SQLConnect error:   Status = -1   SQLState = S1000   Natcode = 0
[ODBC] [IBM(DataDirect OEM)][ODBC Oracle Wire Protocol driver]Cannot open TNS Names file.

这个错误请检查Oracle环境变量配置和文件权限分配,通常文件具有读的权限即可。

3 MySql 数据源配置

配置的方式都是差不多的,理解了工作原理,然后根据官方提供的预配置信息配置。
配置.odbc.ini

[mysql_99]
Driver=/opt/IBM/InformationServer/Server/branded_odbc/lib/VMmysql24.so
Description=DataDirect 6.0 MySQL Wire Protocol
AlternateServers=
ApplicationUsingThreads=1
ConnectionReset=0
ConnectionRetryCount=0
ConnectionRetryDelay=3
DefaultLongDataBuffLen=1024
EnableDescribeParam=0
EncryptionMethod=0
FailoverGranularity=0
FailoverMode=0
FailoverPreconnect=0
HostName=mySqlHost
Database=mysql
PortNumber=3306
HostNameInCertificate=
InteractiveClient=0
KeyPassword=
KeyStore=
KeyStorePassword=
LoadBalanceTimeout=0
LoadBalancing=0
LoginTimeout=15
LogonID=
Password=
MaxPoolSize=100
MinPoolSize=0
Pooling=0
QueryTimeout=0
ReportCodepageConversionErrors=0
TreatBinaryAsChar=0
TrustStore=
TrustStorePassword=
ValidateServerCertificate=1  

这里HostName配置主机,Database mysql数据库,PortNumber 数据库端口。
配置uvodbc.config

<mysql_99>
DBMSTYPE = ODBC

测试数据源 注意8.5版本的DataStage驱动不支持MySQL Community Servers版本,如果测试的版本是MySQL Community Servers,则会得到下面的错误信息。

>ds_connect mysql_99
Enter username for connecting to 'mysql_99' DBMS [dsadm]: root
Enter password for root: 
SQLConnect error:   Status = -1   SQLState = S1000   Natcode = 0
[ODBC] [IBM(DataDirect OEM)][ODBC MySQL Wire Protocol driver]Connections to MySQL Community Servers are not supported.  Please contact MySQL to obtain a MySQL Enterprise or Commercial version.

4 数据源的使用

当在服务器端配置好ODBC数据源后,便可以任何连接到该服务端的客户端中使用,这有利于管理,因为不需要在客户端中做任何的操作,并且服务端的更改对于客户端来说是透明的。

在Data source中输入服务端配置的ODBC数据源名称;
在Username和Password中输入数据库用户名和密码;
单击“测试”按钮测试数据源连接,然后再进行其它开发。

5 总结

  在本文中介绍了DataStage ODBC的安装路径、官方帮助文档、需要配置的文件以及配置方法和注意事项;.odbc.ini是数据源的核心文件,改文件的路径可以在dsenv配置文件中的ODBCINI变量中配置,该文件配置数据源连接的详细信息,如主机、数据库名、端口等信息。uvodbc.config文件配置数据源DSN信息,里面配置的DSN name必须和.odbc.ini的名称相同,该文件存在于项目目录下和$DSHOME目录下,默认项目首先查找和使用项目目录下的uvodbc.config文件,如果未找到则使用$DSHOME目录下uvodbc.config文件,所以使用时注意理解它们的作用和使用范围。通常配置完后建议在服务端中进行测试,然后再在客户端中开发使用,这样可以减少一些未知的错误问题。

--The end(2015-09-28)

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
IBM may not offer the products, services, or features discussed in this document in other countries. Consult your local IBM representative for information on the products and services currently available in your area. Any reference to an IBM product, program, or service is not intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead. However, it is the user's responsibility to evaluate and verify the operation of any non-IBM product, program, or service. IBM may have patents or pending patent applications covering subject matter described in this document. The furnishing of this document does not give you any license to these patents. You can send license inquiries, in writing, to: IBM Director of Licensing, IBM Corporation, North Castle Drive, Armonk, NY 10504-1785 U.S.A. The following paragraph does not apply to the United Kingdom or any other country where such provisions are inconsistent with local law: INTERNATIONAL BUSINESS MACHINES CORPORATION PROVIDES THIS PUBLICATION "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Some states do not allow disclaimer of express or implied warranties in certain transactions, therefore, this statement may not apply to you. This information could include technical inaccuracies or typographical errors. Changes are periodically made to the information herein; these changes will be incorporated in new editions of the publication. IBM may make improvements and/or changes in the product(s) and/or the program(s) described in this publication at any time without notice. Any references in this information to non-IBM Web sites are provided for convenience only and do not in any manner serve as an endorsement of those Web sites. The materials at those Web sites are not part of the materials for this IBM product and use of those Web sites is at your own risk. IBM may use or distribute any of the information you supply in any way it believes appropriate without incurring any obligation to you. Information concerning non-IBM products was obtained from the suppliers of those products, their published announcements or other publicly available sources. IBM has not tested those products and cannot confirm the accuracy of performance, compatibility or any other claims related to non-IBM products. Questions on the capabilities of non-IBM products should be addressed to the suppliers of those products. This information contains examples of data and reports used in daily business operations. To illustrate them as completely as possible, the examples include the names of individuals, companies, brands, and products. All of these names are fictitious and any similarity to the names and addresses used by an actual business enterprise is entirely coincidental. COPYRIGHT LICENSE: This information contains sample application programs in source language, which illustrate
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值