Friday, April 02, 2010

SQL Server 2005 Linked Server to Oracle 10g

We have a need for our Microsoft SQL Server 2005 Standard Edition Service Pack 3 system to talk with our main Oracle 10g 10.2.0.4 server.  I set this up as a linked server by doing the following:

  1. Install either the 10g or 11g Oracle client on your Microsoft SQL Server, make sure you do an Administration installation, not just the run-time or instant client.
  2. I used the Net Configuration wizard to setup the TNSNAMES.ORA file with a reference to our primary Oracle server
  3. Restart your SQL Server, this confirms that all of the Oracle software can be found in the system path and by your SQL Server
  4. I opened Microsoft SQL Server Management Studio and then a New Query Window
  5. I executed the following T-SQL statement:  EXEC sp_addlinkedserver 'APP_ABC', 'Oracle', 'OraOLEDB.Oracle', 'BIGDADDY'
    1. APP_ABC = the name I want to reference this connection as
    2. Oracle = name of the product I'm connecting to
    3. OraOLEDB.Oracle = This is the Oracle OLE DB provider, I wasn't able to get the Microsoft one to work correctly, but this one worked straight-away
    4. BIGDADDY = the TNS name that's setup to reference my Oracle server
  6. In my case, we wanted to have the Linked Server connection use a specifically created Oracle login account for the connection.  I setup this account for my linked server by executing the following T-SQL statement:  EXEC sp_addlinkedsrvlogin 'APP_ABC', false, NULL, 'APP_USER_ACCOUNT ',   'jDUEhdt73ndhD37dU'
    1. APP_ABC = name of the linked server connection
    2. false = tells the connection not to use the SQL Server login account to try and authenticate against the Oracle server
    3. NULL = sorry, I forget what this one is for
    4. APP_USER_ACCOUNT = Oracle user account for the Linked Server connection
    5. jDUEhdt73ndhD37dU = Oracle user account password for the Linked Server connection
  7. At this point you should be able to perform a SELECT query using something like:  SELECT NAME FROM APP_ABC..SCOTT.TEAMS ORDER BY NAME;
    1. NAME = fields to select from the table
    2. APP_ABC = Linked Server connection
    3. .. = two dots to skip the catalog reference
    4. SCOTT = schema that has the table or view
    5. TEAMS = table to retrieve the data from
This how I configured the connection.  Took me about an hour to figure out and setup, hopefully this will get you running much faster then that!

2 comments:

Anonymous said...

great ! it helped me a lot, I got it configured in a couple of minutes

Anonymous said...

If I dont come back to say thank you very much, am appreciative.

Thanks a bunch.