尝试使用ODP .NET连接时出现ORA-12154错误
更新:Wernfried的回答为我解决了.
创建一个环境变量TNS_ADMIN = D:\ oracle\product\12.1.0\dbhome_1 \network\admin
Sqlplus从Registry读取TNS_ADMIN但ODP.NET托管驱动程序不读取注册表.另请参阅: OdbcConnection将中文字符返回为"?"
您可以通过以下方式检查环境变量:
string tns_admin = Environment.GetEnvironmentVariable("TNS_ADMIN")
我并没有完全理解他建议的链接是如何相关的.
原始问题:
尝试使用ODP .NET连接时出现ORA-12154错误
代码:
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-plus连接:
C:\Users\Derek.Morin\Documents\Visual Studio 2010\Projects\ScriptCode\Oracle>sqlplus redacted/redacted@localhost/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
Derek.. 7
韦恩弗里德的评论为我解决了这个问题.由于他没有回来发布它作为答案 - 我将以他的评论结束这一点.
创建一个环境变量
TNS_ADMIN=D:\oracle\product\12.1.0\dbhome_1\network\admin
sqlplus从Registry读取TNS_ADMIN但ODP.NET托管驱动程序不读取注册表.另见stackoverflow.com/questions/28280883/... - Wernfried Domscheit 2015年12月10日16:24
韦恩弗里德的评论为我解决了这个问题.由于他没有回来发布它作为答案 - 我将以他的评论结束这一点.
创建一个环境变量
TNS_ADMIN=D:\oracle\product\12.1.0\dbhome_1\network\admin
sqlplus从Registry读取TNS_ADMIN但ODP.NET托管驱动程序不读取注册表.另见stackoverflow.com/questions/28280883/... - Wernfried Domscheit 2015年12月10日16:24