ORA-12154错误尝试使用ODP .NETORA-12154错误尝试使用ODP .NET
UPDATE连接到连接:Wernfried的答案固定对我来说。
Create an environment variable TNS_ADMIN=D:\oracle\product\12.1.0\dbhome_1\network\admin
Sqlplus reads TNS_ADMIN from Registry but ODP.NET Managed Driver does not read the registry. See also: OdbcConnection returning Chinese Characters as "?"
您可以检查环境变量会被设为:
string tns_admin = Environment.GetEnvironmentVariable("TNS_ADMIN")
我不太明白,他建议该链接是如何相关的。
原题:
ORA-12154错误尝试使用ODP .NET
的代码连接:
OracleConnection oracleConnection = new OracleConnection();
string connectionString = "User Id=redacted;Password=redacted;Data Source=db6";
oracleConnection.ConnectionString = connectionString;
oracleConnection.Open();
错误:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Oracle.ManagedDataAccess.Client.OracleException: ORA-12154: TNS:could not resolve the connect identifier specified ---> OracleInternal.Network.NetworkException: ORA-12154: TNS:could not resolve the connect identifier specified
at OracleInternal.Network.AddressResolution..ctor(String TNSAlias, String instanceName)
at OracleInternal.Network.OracleCommunication.DoConnect(String tnsDescriptor)
at OracleInternal.Network.OracleCommunication.Connect(String
我的tnsnames .ora:
# tnsnames.ora Network Configuration File: D:\oracle\product\12.1.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
DB6 =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = redacted.redacted.com)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = db6)
)
)
LISTENER_DB6 =
(ADDRESS = (PROTOCOL = TCP)(HOST = redacted.redacted.com)(PORT = 1521))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
与SQL加连接:
C:\Users\Derek.Morin\Documents\Visual Studio 2010\Projects\ScriptCode\Oracle>sqlplus redacted/[email protected]/db6
SQL*Plus: Release 12.1.0.1.0 Production on Thu Dec 10 09:10:14 2015
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Last Successful login time: Tue Sep 22 2015 09:41:19 -05:00
Connected to:
Oracle Database 12c Release 12.1.0.1.0 - 64bit Production
您的计算机上是否配置了多个Oracle Home? – sstan
我知道只有一个。除非通过nuget安装odp .net创建另一个。 – Derek
我注意到你通过'sqlplus'连接使用'@ localhost/db6'来完成。你只能使用'@ db6'连接'sqlplus'吗?你是否也试过从命令行运行'tnsping db6'? – sstan