Search code examples
vb.netoracleserviceodp.net

ODP.NET ORA-12154 TNS error only when run as service


I am writing a service in VB.NET to continually log data to an Oracle DB using ODP.NET

The application was originally written as a basic Windows Forms App and works however when I port it to a service it seems it cannot see the TNS file and the following error message is thrown:

Service cannot be started. Oracle.DataAccess.Client.OracleException
ORA-12154:TNS:could not resolve the connect identifier specified    

So when using the following example connectstring

"Data Source= example;User Id= user;Password=password;"

I get ORA-12154

If I provide the full TNS entry directly to the app e.g

"Data Source= (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = EXAMPLE)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = EXAMPLE) ) );User Id= user;Password=password;"

Then it works but when I originally developed the app as a Forms Application it worked either way.

I assumed maybe the environment variables were not set up correctly but I have added the required system variables (ORACLE_HOME / TNS_ADMIN / added the oracle folder to PATH) and it doesnt work.

The path the service is being run/was installed from does not contain parentheses, I have checked the process with process monitor and it looks like it is being started up with the correct environment variables (ORACLE_HOME / TNS_ADMIN / PATH are all there and correct). The machine being used for testing is running Win XP

What am I missing here?

Thanks


Solution

  • I suspect that the user that the service runs as will need file system permission to the entire oracle directory tree. This feels like a permissions problem, since it can't resolve the connect identifier, but works if it doesn't need to.

    Try adding read permission to the entire oracle client directory for whatever user that the service is running as.