问题
I have moved a component of our application from a webservice to a Windows Service. It connects to oracle perfectly from the webservice but refuses to see the Tns names from the Windows service. I have given full control to the ORAHOME dir to the account the service is running under.
I have also checked the service account permission to the registry by using runas regedit as the service account and it can see HKLM\SOFTWARE\ORACLE\HOME0 details and HKLM\SOFTWARE\ORACLE\ALL_HOMES. All the ORACLE_HOME keys are pointing to the same directory.
I can log in as the service account and TNSPing the sid 'UAT' with no problems:
'OK (70 msec)'
I have attached process monitor to the process and the service account is (finally after scanning most of the registry) seeing the tnsnames.ora and even reads it.
Are you chuckling behind your keyboard? Can you help!
Cause: OracleException
Source: System.Data.OracleClient
Message: ORA-12154: TNS:could not resolve service name
at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OracleClient.OracleConnection.Open()
回答1:
First you can 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;
Then you get the real error:
And got ‘ORA-06413: Connection not open.’
Which was due to the 'Windows Service' path having brackets in it '(DEV)' or '(UAT)'
ANSWER: Expand out the connection string to exclude the TNS resolution and then make sure that the path to the calling application does not contain brackets '(' or ')'.
回答2:
Try setting the windows environment variable TNS_ADMIN to the path where the tnsnames.ora file resides and restarting your serivce.
回答3:
Run Process Monitor to see if it's loading the TNSNAMES.ORA file. I suspect it is, but your name resolution is broken as that user.
If you can log in interactively with the service account, try using tnsping to see if you can connect to the name.
Oracle resolves files in this order (as per Metalink article 114085.1):
- Oracle Net files in present working directory
- TNS_ADMIN defined as a user/session environment variable
- TNS_ADMIN defined as a global environment variable
- TNS_ADMIN defined in the registry
- Oracle Net files in %ORACLE_HOME%\network\admin (the Oracle default location)
See which, if any, are being read with Process Monitor.
回答4:
Check that the service can access the registry entry with tells oracle where the tnsnames.ora file is located. From memory it is HKLM\SOFTWARE\ORACLE\Key_Client with a TNS_NAMES registry string which is the folder holding the tnsnames.ora file. You can also create the same thing in the HKCU tree.
Oops ! now i'm at work i can see the string name should be TNS_ADMIN. Also try the env variable TNS_ADMIN and make sure there is nothing in HKCU.
Noticed as well you need the sqlnet.ora file in the same folder as tnsnames.ora
回答5:
First of all check your operating system is it 32bit or 64bit. If it is 64bit then install oracle express edition 64bit then it will not generate any error and run successfully....
visit http://behindfutureworld.weebly.com for more detail.....
来源:https://stackoverflow.com/questions/704772/windows-service-in-net-cannot-resolve-tns-service-name