Monday, May 3, 2010

Linked Server between SQL 2005 and Oracle

SQL Server Linked Servers feature grants access to Oracle data and data from other OLEDB/ODBC compatible data sources from SQL Server.




1. Install and Configure the Oracle Client Software
Oracle client software provides the network libraries required to establish connectivity to an Oracle Database system.Download the software from http://www.oracle.com/technology/software/products/database/oracle10g/index.html. Install the software on your SQL Server system and configure it by using Oracle Net Configuration Assistant.
2. Create a Linked Server
Create a linked server by executing the following command

EXEC sp_addlinkedserver 
  'OracleLinkedServer', 'Oracle', 
  'MSDAORA', 'OracleServer'


3. Add Logins for the Linked Server
Next, provide the SQL Server system with an Oracle login to access the Oracle database by using the sp_addlinkedsrvlogin command
EXEC sp_addlinkedsrvlogin ' 
  OracleLinkedServer ', false, 
  'SQLuser', 'OracleUser', 
  'OraclePwd' 
The first parameter, Oracle Linked Server, specifies the name of the linked server system that you created.The second parameter determines the name of the login to be used on the remote system.A value of True indicates that the current SQL Server login will be used to connect to the linked server. This requires that the logins on the two database servers match, which is typically not the case.A value of False means you'll supply the remote login.The third parameter specifiesthe name of a SQL Server login that this remote login will map to.A value of NULL indicates that this remote login will be used for all connections to the linked Oracle server. If the Oracle system uses Windows authentication, you can use the domain\ to specify a Windows login. The fourth and fifth parameters supply login and password values for the Oracle system.
4. Query the Linked Server 
To test the connection, run a sample query using the linked server name. Linked servers support updates as well as queries.To access the tables on a linked server, use a four-part naming syntax:linked_server_name.catalog_ name.schema_name.table_name. For example, to query the sample Oracle Scott database, you'd enter the statement

SELECT * FROM 
  OracleLinkedServer..SCOTT.EMP 

No comments:

Post a Comment