gpt4 book ai didi

oracle - 尝试使用 ODP .NET 进行连接时出现 ORA-12154 错误

转载 作者:行者123 更新时间:2023-12-04 03:50:13 36 4
gpt4 key购买 nike

尝试使用 ODP .NET 进行连接时出现 ORA-12154 错误

更新: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")

我不太明白他建议的链接是如何相关的。

原问题:

尝试使用 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

最佳答案

Wernfried 的评论为我修复了它。由于他没有回来将其作为答案发布 - 我将用他的评论结束此评论。

创建环境变量

TNS_ADMIN=D:\oracle\product\12.1.0\dbhome_1\network\admin

sqlplus 从注册表读取 TNS_ADMIN 但 ODP.NET 托管驱动程序不读取注册表。另请参阅 stackoverflow.com/questions/28280883/... – Wernfried Domscheit 2015 年 12 月 10 日 16:24

关于oracle - 尝试使用 ODP .NET 进行连接时出现 ORA-12154 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34206659/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com