Ora 12154 error

2019-02-24 22:13发布

I recently deploy one web application in one of my development servers. I'm using oracle, asp.net and c#. When I run the application in the server everything works fine, but when I try to run the application outside of the server (using my pc, for example) i get this error:

ORA-12154: TNS:could not resolve the connect identifier specified

If i run the application in my pc with visual studio it works fine.

Oracle is installed in Server "A" and the application is in server "B". Server "A" is in one domain and server "B" is in other domain.My pc is in the same domain has Server "A".

In my pc I can find the file tnsname.ora in C:\oracle\product\10.2.0\client_1\NETWORK\ADMIN, but in Server "B" i can´t find it anywhere

any idea? Thanks for the help.

9条回答
Summer. ? 凉城
2楼-- · 2019-02-24 23:16

Guess: An oracle client is not installed on Server B.

If you do have an oracle client installed then you can still put a tnsnames file in any location (Such as a directory on a network share). In order to do this, set a TNS_ADMIN system variable (System Properties->Advanced->Environment Variables on XP) to the directory containing your tnsnames files.

For me for example I have a system variable: TNS_ADMIN - C:\oracle\ora92\network\ADMIN

查看更多
聊天终结者
3楼-- · 2019-02-24 23:18

It seems you need to install Oracle Client on "Server B" (the application server), and configure it's TNSNAMES.ORA file. This is required since otherwise, the running code will have no idea where to look for the database you use in the application (probably you're configured a data source in web.config or hard-coded something). Remember - you cannot access Oracle (easily) without Oracle Client.

查看更多
做个烂人
4楼-- · 2019-02-24 23:18

I had faced the similar issue. The below code was working in my system but was not working in another server even though I had added a tns entry in tnsnames.ora file.

con = new OracleConnection();
con.ConnectionString = "User Id=username;Password=password;Data Source=uit45";
con.Open(); // throws error here

After digging and digging, I found out the solution for this. We need to ignore the entry in tns file and can be given tns entry as connection string, which worked fine for me. Try the below code.

con = new OracleConnection("Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=db-uit45.xxx)(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SID=uit45)));User Id=username;Password=password");
con.Open();

Note that you need to give the associated values, especially for HOST,PORT,SID,User Id and Password.

查看更多
登录 后发表回答