views:

66

answers:

3

I'm trying to link SQL Server 2005 to an Oracle 10g database. I've installed the Oracle client on the SQL server and validated that I can connect to the Oracle database using both tnsping and sqlplus. When I try to run a query in SQL Server I get the following:

OLE DB provider "OraOLEDB.Oracle" for linked server "ORA_CSSA2APD" returned message "ORA-12154: TNS:could not resolve the connect identifier specified".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "OraOLEDB.Oracle" for linked server "ORA_CSSA2APD".

Any ideas? I've tried both of the following queries with no luck:

select * from openquery(ORA_CSSA2APD, 'select count(rowid) from eservice_op.agent')

select count(rowid) from ORA_CSSA2APD..eservice_op.agent

+2  A: 

TNS error messages generally means the connection is flawed (eg host is unobtainable/timesout on the specified port, or that is simply doesn't know what ORA_CSSA2APD is supposed to point to).

One thing to consider is, are you using a 64-bit Windows and are you using a 32-bit or 64-bit Oracle client (or possibly both). If you've got a 32-bit app running on a 64-bit OS trying to call Oracle, it needs a 32-bit Oracle client. Using a 32-bit client on a 64-bit OS can be tricky and it is safer to NOT install it in the "Program Files (x86)" folder.

Also bear in mind the following

In a 64-bit version of Windows Server 2003 or of Windows XP, the %WinDir%\System32 folder is reserved for 64-bit applications. When a 32-bit application tries to access the System32 folder, access is redirected to the following folder: %WinDir%\SysWOW64

So for 64-bit windows, the 32 bit stuff is in the SysWOW64 folder and the 64 bit stuff is in the system32 folder.

Gary
Both the OS and the Oracle client are 32-bit.
timrcase
+2  A: 

ORA:12154 generally means that the alias of the db you're trying to connect to wasn't found in the tnsnames.ora file. (See http://ora-12154.ora-code.com/ a more detailed explanation.)

You need to make sure that the Data Source is an alias that the tnsnames file knows about (on the server where SQL Server resides, regardless of where you're running the queries from); SQL Server is going to be just like any other Oracle client and needs to know where to connect to and without the tnsnames.ora file, it's not going to know the details of where the Oracle db is.

If you don't have access to the SQL Server server (there's one from the department of redundancy department), you'll need to get the server admin to set that up for you.

(The Data Source property of the linked server should be the alias in tnsnames.ora alias for the db you're trying to link to.)

HTH...

Patrick Marchand
+1 - Most likely this. The error is very specific.
REW
I am able to connect using SQLPlus and I can successfully tnsping the server so there is no problem with the tnsnames file and I'm using the same service name I specified in the tnsnames as the @datasrc argument of the sp_addlinkedserver command. Any other ideas?
timrcase
And SQLPlus running on the same machine as SQL Server?
Patrick Marchand
Yes, it is running on the same machine as SQL Server.
timrcase
In your SQLNET.ORA file, do you have an entry that looks something like:NAMES.DEFAULT_DOMAIN = WORLD?If so, it will expect your aliases in the tnsnames.ora file to end in .WORLDFor example, if the default_domain is WORLD, instead of having this:ORCL = (DESCRIPTION = ...etc...)you would need this:ORCL.WORLD = (DESCRIPTION = ...)
Patrick Marchand
There are the only two lines in my sqlnet.ora file:SQLNET.AUTHENTICATION_SERVICES= (NTS)NAMES.DIRECTORY_PATH= (TNSNAMES)
timrcase
Has SQL Server been restarted since the Oracle client was installed?
Patrick Marchand
Yes, a few times.
timrcase
A: 

I suspect an environment setting. That is, your session is picking up the TNSNAMES.ORA file but the session underlying SQL Server is not. I'd check were ORACLE_HOME and, possibly, TNS_ADMIN are being set and pointing to.

Are you able to use the easy connect syntax for the database with the SQL Server connection .

IE replace ORA_CSSA2APD with hostname:1521/service_name

Gary
The environment variables for both are set and accurate. I haven't tried the connect syntax you outlined above, but I did try creating a UDL and copying that into the connection string with no luck. I'll try your syntax above and let you know the results. I appreciate it.
timrcase
I restarted the service because I wasn't sure if I had since I set the TNS_ADMIN environment variable and everything is working now. Thanks for the help!
timrcase