Oracle的OLEDB
转自 http://dingfeng-cn.spaces.live.com/blog/cns!24ad96ecbc21cefa!124.entry
最近在处理两个问题,都是sqlserver用linkserver连接oracle的问题。
使用了oracle提供的OLEDB,发现各个版本居然都在报错,我FT!
在metalink上查了半天,也没什么有用的信息。大部分都是没有解决的case。
只总结了以下两种情况:
原则:
尽量使用同一版本的oracle的client和server。
至于8i的版本,oracle自己都不支持了。可以尝试升级到817的最后一个版本,可能能解决问题。
1. Oracle client 10.1.0.2 --oracle server 10g
oracle中table :test(cc char(2))
在linkserver中操作oracle的table:test
insert into ORACLE..DLINGER.TEST values('cc')
成功
select * from ORACLE..DLINGER.TEST
Server: Msg 7320, Level 16, State 2, Line 1
Could not execute query against OLE DB provider 'OraOLEDB.Oracle'.
OLE DB error trace [OLE/DB Provider 'OraOLEDB.Oracle' ICommandText::Execute returned 0x80040155].
解决方法:
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSSQLServerProvidersORAOLEDB.ORACLEAllowInProcess
value改成1
2. Oracle client 9204 --oracle server 9204
table:test1(cc int)
select * from test..DLINGER.TEST1
服务器: 消息 7356,级别 16,状态 1,行 1
OLE DB 提供程序 'OraOLEDB.Oracle' 为列提供的元数据不一致。执行时更改了元数据信息。
OLE DB 错误跟踪[Non-interface error: Column 'DUMMY' (compile-time ordinal 1) of object '"DLINGER"."TEST"' was reported to have a DBTYPE of 129 at compile time and 130 at run time]。
这里我们发现当使用有精度的数据类型的时候,这个查询是不会报这种元数据类型不匹配的错误的。
这个是oracle的bug:3117040 在9.2.0.4.10中修正。
那么如果oracle的版本低于这个,避免在sqlserver的link seerver需要访问的column中使用没有精度的数据类型。
create table abc(col1 number(10)); OK
create table abc1(col1 number(38)); OK
create table abc1(col1 number(38,2)); OK
create table abc2(col1 float(126)); OK
create table abc3(col1 varchar2(4000)); OK
create table abc4(col1 varchar2(255)); OK
create table abc5(col1 date); OK
create table abc6(col1 char(20)); OK
create table abc7(col1 char(2000)); OK
create table abc8(col1 long); ERROR
create table abc9(col1 integer); ERROR
create table abc10(col1 float(50)); OK
create table abc11(col1 blob); OK
create table abc12(col2 clob); ERROR
注意:timestamp的数据类型是不支持的。
create table test3(col2 number(38,2));
select * from test..DLINGER.TEST3
这个问题解决了之后,我们发现又返回了另一个错误:
服务器: 消息 7320,级别 16,状态 2,行 1
未能对 OLE DB 提供程序 'OraOLEDB.Oracle' 执行查询。
OLE DB 错误跟踪[OLE/DB Provider 'OraOLEDB.Oracle' ICommandText::Execute returned 0x80040155]。
这个和10g中的错误是一致的,我们同样查看注册表的键值:
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSSQLServerProvidersORAOLEDB.ORACLEAllowInProcess,
在我的9i的环境下注册表中没有相关的项,手工添加它,key值为1。
现在可以执行查询了。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7811640/viewspace-407158/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7811640/viewspace-407158/