1、 首先本机安装db2客户端;
2、 在db2中建立到远程db2数据库的连接;
3、 在odbc中建立到本机db2的连接,此处名字需要记住;
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" /><shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"><stroke joinstyle="miter"></stroke><formulas><f eqn="if lineDrawn pixelLineWidth 0"></f><f eqn="sum @0 1 0"></f><f eqn="sum 0 0 @1"></f><f eqn="prod @2 1 2"></f><f eqn="prod @3 21600 pixelWidth"></f><f eqn="prod @3 21600 pixelHeight"></f><f eqn="sum @0 0 1"></f><f eqn="prod @6 1 2"></f><f eqn="prod @7 21600 pixelWidth"></f><f eqn="sum @8 21600 0"></f><f eqn="prod @7 21600 pixelHeight"></f><f eqn="sum @10 21600 0"></f></formulas><path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"></path><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><lock aspectratio="t" v:ext="edit"></lock></shapetype><shape id="_x0000_i1025" style="WIDTH: 414.75pt; HEIGHT: 311.25pt" type="#_x0000_t75"><imagedata o:title="" src="file:///C:%5CDOCUME~1%5Czwd_bs%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image001.png"></imagedata></shape>
4、 在oracle进行如下配置:
先配置oracle到odbc的初始化信息,看是否有inithsodbc.ora这个文件,一般默认安装都有;
<shape id="_x0000_i1026" style="WIDTH: 414.75pt; HEIGHT: 311.25pt" type="#_x0000_t75"><imagedata o:title="" src="file:///C:%5CDOCUME~1%5Czwd_bs%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image003.png"><font color="#000000" size="3"></font></imagedata></shape>
建立文件inithsdb.ora,名字可以为其他,如果通过odbc建立到多个db2的连接,可以在建几个init***.ora的文件,需要注意的是,JQYXGIS要与ODBC中的名字一致,hsdb要与init***.ora *号部分的名字一致;
<shape id="_x0000_i1027" style="WIDTH: 431.25pt; HEIGHT: 324pt" type="#_x0000_t75"><imagedata o:title="" src="file:///C:%5CDOCUME~1%5Czwd_bs%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image005.png"><font color="#000000" size="3"></font></imagedata></shape>
修改linster.ora 文件,注意修改SID_NAME 与上面名字一致;
(SID_DESC =
(GLOBAL_DBNAME = HSODBCDB)
(PROGRAM = hsodbc)
(SID_NAME = hsdb)
(ORACLE_HOME = D:\oracle\ora92)
)
<shape id="_x0000_i1028" style="WIDTH: 431.25pt; HEIGHT: 324pt" type="#_x0000_t75"><imagedata o:title="" src="file:///C:%5CDOCUME~1%5Czwd_bs%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image007.png"><font color="#000000"></font></imagedata></shape>
修改tnsnames.ora;
ODBCDB2 =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = server)(PORT = 1521))
)
(CONNECT_DATA =
(SID = hsdb)
)
(HS = OK)
)
<shape id="_x0000_i1029" style="WIDTH: 431.25pt; HEIGHT: 324pt" type="#_x0000_t75"><imagedata o:title="" src="file:///C:%5CDOCUME~1%5Czwd_bs%5CLOCALS~1%5CTemp%5Cmsohtml1%5C01%5Cclip_image009.png"><font color="#000000"></font></imagedata></shape>
在plsql中建立data_link,命令如下:
create public database link db2_szhcc
connect to "wen" identified by " wen "
using 'odbcdb2'
需要注意的是,用户名、密码这里需要用双引号,否则出现用户名、密码无效的错误。
最后一步是校验连接是否正确:
select * from wen.tb_cig_order@odbcdb2