Friday, December 03, 2010

ORA-12154: TNS:could not resolve service name with .NET Windows Services

When I try to connect to oracle database from a .NET Windows service I get the following error.

ORA-12154: TNS:could not resolve service name

a) Tried fixing the NTFS permissions on the oracle folder for the user account running the service.

b) Checked the tnsnames.ora and sqlnet.ora is available and service name is configured in it.

Still I got the same error. If I try to connect to the oracle database from the same server using .NET Windows Forms or Console application, the connection established successfully.

Solution

Change the connection string to expand out the tns entry:

Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=10.161.50.101)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=MOUAT)));Password=password;User Id=username;

This will give the real error:

And got 'ORA-06413: Connection not open.'

Which was due to the 'Windows Service' path having brackets in it.

Change the connection string to exclude the TNS resolution and then make sure that the path to the calling application does not contain brackets '(' or ')'.

No comments:

Post a Comment