Can't connect to Oracle from a windows service (error: ORA-12154: TNS:could not resolve service name (12154) )

ぐ巨炮叔叔 提交于 2019-12-05 08:21:47
Nicola Musatti

Environment variables you define in the corresponding dialog are not available to Windows services. One thing you can try is to expand your connection string as described in this post. Other suggestions from the same post may be applicable.

It probably does not find the tnsnames.ora file. Make sure that the same environment variables are set when you start the service.

Make sure that the service account has permissions to read the tnsnames.ora file. Also in sqlnet.ora try removing NTS from SQLNET.AUTHENTICATION_SERVICES if it is there.

If your are still struggling try using ezconnect to bypass tns names all together ex: //ip.of.server/sid

http://www.orafaq.com/wiki/EZCONNECT

John C: A couple of things seemed odd to me. I hope I have not misunderstood your replies.

In the connection string in one of the replies, you got an error about the missing driver. To fix this you will have to mention the provider/driver since you are using the OdbcConnection and not an OracleConnection. The OracleConnection that most people would use would implicitly point the to the driver. I assume you need to service to work across databases so the OdbcConnection is required. The website gives a lot of examples for connection strings and I think you should find something that fits.

I would suggest you try

Driver={Microsoft ODBC for Oracle};CONNECTSTRING=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=server)(PORT=7001))(CONNECT_DATA=(SERVICE_NAME=myDb)));Uid=myUsername;Pwd=myPassword;

Another thing was the location that your TNS_ADMIN variable pointed to. You had mentioned that you pointed to OraHome. I just wanted to confirm that you pointed the variable to the NETWORK \ ADMIN folder within OraHome. I believe you will have to point to the folder where the file exists.

Finally I would suggest you try and take some of the parameters out of the connection string you have in the original post. It would reduce the variables that can affect the outcome, making it easier to debug. And have the environment variable which are configured for the user as system environment variables. Perhaps the reason you winforms application works is because of a variable defined for the user. I suspect that windows service may only use system variables.

Driver={Oracle in OraHome92};Server=myServerAddress;Dbq=myDataBase;Uid=myUsername;Pwd=myPassword;

OK, I'm going to answer my own question here just to keep the final resolution separate from the helpful suggestions that led me to it. The post referenced by Nicola )once I read it carefully) turned out to have the answer. My service was running from Program Files(x86) and the oracle driver can NOT handle ( ) in the path of the calling app.
I moved my service to D:\ServiceTest and it works fine. My problem now is that I don't think our app can be moved out of Program Files (x86).
Thank you all for your help, I appreciate everyone's input but I will have to give the bounty to Nicola, as he pointed me to the post that contained the answer. Thanks again for all your help

Verify that the TNS Name definition does not have spaces before the name in the tnsnames.ora

Andrewpaul

I have fixed the problem.

there was a '@' character in the password of my database. After I changed the password and remove that character, the problem has been fixed and the export operation has completed successfully.

This link was helpful in solving the issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!