sp_addlinkersrvlogin从oracle查询数据

发表于:2007-06-20来源:作者:点击数: 标签:
摘自fengfangfang专栏 代码只有三句: sp_addlinkedserver ' oracle link', ' Oracle ','MSDAORA', 'oracl .net name' /* 其中oraclelink是要在 sql 中使用的名称, oraclenetname是oracle 网络 服务名称。 */ go sp_addlinkedsrvlogin 'oraclelink', 'false'

   

摘自fengfangfang专栏

代码只有三句:
sp_addlinkedserver 'oraclelink', 'Oracle', 'MSDAORA', 'oracl.netname'
/*
其中oraclelink是要在sql中使用的名称,
oraclenetname是oracle网络服务名称。
*/
go
sp_addlinkedsrvlogin 'oraclelink', 'false', 'sa', 'oracleuserid', 'oraclepwd'
/*
其中oraclelink是要在sql中使用的名称,是在sp_addlinkedserver定义的;
sa是sql中的用户,
oracleuserid是oracle数据库的登录名称,oraclepwd是oracleuserid的密码。
*/
go
 
SELECT * FROM oraclelink..ORACLEUSERID.AREA AREA_1
go
/*
用户名和表名ORACLEUSERID.AREA一定要大写,否则将会得到如下错误信息:
 
服务器: 消息7314,级别16,状态1,行1
OLE DB 提供程序'oraclelink' 不包含表'"oracleuserid"."AREA"'。该表可能不存在,或当前用户没有使用该表的权限。
OLE DB 错误跟踪[Non-interface error:  OLE DB provider does not contain the table: ProviderName='oraclelink', TableName='"oracleuserid"."AREA"']。
 
英文为提示为:
Server: Msg 7314, Level 16, State 1, Line 0
OLE DB provider 'oraclelink' does not contain table '"oracleuserid"."AREA"'.  The table either does not exist or the current user does not have permissions on that table.
OLE DB error trace [Non-interface error:  OLE DB provider does not contain the table: ProviderName='oraclelink', TableName='"oracleuserid"."AREA"'].
 
 
当前使用的用户,也就是使用企业管理器或查询分析器连接SQL Server的用户一定是sp_addlinkedsrvlogin中设置的用户,上面使用的是sa
如果使用windows集成验证,将会得到如下错误信息:
 
服务器: 消息7399,级别16,状态1,行1
OLE DB 提供程序'MSDAORA' 报错。验证失败。
[OLE/DB provider returned message: ORA-01004: 不支持默认用户名特性;登录被拒绝]
OLE DB 错误跟踪[OLE/DB Provider 'MSDAORA' IDBInitialize::Initialize returned 0x80040e4d:  验证失败。]。
 
英文为提示为:
 
Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'MSDAORA' reported an error. Authentication failed.
[OLE/DB provider returned message: ORA-01004: default username feature not supported; logon denied]
OLE DB error trace [OLE/DB Provider 'MSDAORA' IDBInitialize::Initialize returned 0x80040e4d: Authentication failed.].
 
*/

原文转自:http://www.ltesting.net