EXEC master.dbo.sp_MSset_oledb_prop 'ORAOLEDB.Oracle', N'AllowInProcess', 1
GO
EXEC master.dbo.sp_MSset_oledb_prop 'ORAOLEDB.Oracle', N'DynamicParameters', 1
GO
--建立Oracle連結伺服器,使用EZConnect的方法就免設TNSname了
EXEC sp_addlinkedserver 'LK_ORA', 'Oracle', 'OraOLEDB.Oracle', '//127.0.0.1:1521/SID_NAME';
GO
--加入驗證的資訊
EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname = N'LK_ORA',
@locallogin = NULL ,
@useself = N'False',
@rmtuser = N'user',
@rmtpassword = N'pwd';
GO
--測試一下吧,可以用四部分名稱
SELECT COLUMNNAME FROM LK_ORA..SCHEMA.TABLENAME;
--也可以用OPENQUERY
SELECT * FROM OPENQUERY(LK_ORA, 'SELECT COLUMNNAME FROM
SCHEMA.TABLENAME')
--如要用EXEC的就要啟用RPC OUT
EXEC master.dbo.sp_serveroption @server=N'LK_ORA', @optname=N'rpc out', @optvalue=N'true'
GO
--啟用後就可以用EXEC的方式囉
EXEC ('select 1 a from dual') at
LK_ORA;
GO
EXEC ('SELECT COLUMNNAME FROM TABLENAME WHERE ROWNUM < 10') at LK_ORA;
GO
0 意見:
張貼留言