OracleConnection.Open 抛出 ORA-12541 TNS no listener
Posted
技术标签:
【中文标题】OracleConnection.Open 抛出 ORA-12541 TNS no listener【英文标题】:OracleConnection.Open is throwing ORA-12541 TNS no listener 【发布时间】:2012-09-16 06:54:01 【问题描述】:所以我通过 C# 连接到外部服务器。我刚刚在我的机器上安装了 Oracle 11g 客户端:http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html(一个 255MB)。
在阅读了许多博客/问题后,我发现这篇文章很有用:
http://dbaspot.com/oracle-faq/444787-ora-12541-tns-no-listener.html
那么这是正确的吗?我什么都做不了。 DBA 必须编辑 LISTENER.ORA 文件?
我的 tnsnames.ora 看起来像这样:
TestingConnect=
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = TestHostName.us.local)(PORT = 1523))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = TEST)
)
)
这让我犯了错误:
Oracle.DataAccess.Client.OracleConnection connection = new Oracle.DataAccess.Client.OracleConnection();
connection.ConnectionString = "Data Source=TestHostName.us.local;Persist Security Info=True;" + "User ID=tesName;Password=test";
connection.Open() //Throwing ERR!!!
我该怎么办?我感谢任何cmets。谢谢!
【问题讨论】:
您确定您的主机名“TestHostName.us.local”是正确的吗?您是否从命令行使用“tnsping TestingConnect”检查数据库是否可访问? 这个错误有很多原因。如果您想消除必须有一个 TNSNames.ora 条目,您可以尝试使用 TNS-less 连接字符串。见 ... connectionstrings.com/oracle 只是看看这是否有效。这可能无法解决问题,但可以消除 TNSNames.ora 的问题。 【参考方案1】:您可以通过以下几种方式做到这一点: 使用您的 TNSNames 文件,数据源应指定 TNSHosts 条目名称(tnsnames.ora 中第一个“=”之前的位),而不是主机名:
connection.ConnectionString = "Data Source=TestingConnect;Persist Security Info=True;" + "User ID=tesName;Password=test";
或者您可以将整个 TNS 条目放在连接字符串中,如下所示:
connection.ConnectionString = "Data Source=(DESCRIPTION = " +
"(ADDRESS = (PROTOCOL = TCP)(HOST = TestHostName.us.local)(PORT = 1523))" +
"(CONNECT_DATA =" +
"(SERVER = DEDICATED)" +
"(SERVICE_NAME = TEST))" +
");Persist Security Info=True;User ID=tesName;Password=test";
【讨论】:
【参考方案2】:感谢您的所有意见。我改变了我的连接字符串,它工作。这是它的样子:
private static string GetConnectionString()
return "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=TestHostName.us.local)(PORT=1523) ) )" +
"(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=CCDB)));User id=UserName; Password=Password; enlist=false; pooling=false;";
【讨论】:
【参考方案3】:在我的情况下,当驱动器C已满时发生此错误,影响是Oracle服务运行不稳定..
Oracle.ManagedDataAccess.Client.OracleException (0x80004005):
ORA-12541: TNS: No listener
---> OracleInternal.Network.NetworkException (0x80004005):
ORA-12541: TNS: No listener
---> System.Net.Sockets.SocketException (0x80004005):
No connection could be made because the target machine actively refused it ServerIP:1521
at System.Net.Sockets.Socket.InternalEndConnect(IAsyncResult asyncResult)
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at System.Net.Sockets.TcpClient.EndConnect(IAsyncResult asyncResult)
at OracleInternal.Network.TcpTransportAdapter.Connect(ConnectionOption conOption)
at OracleInternal.Network.OracleCommunication.DoConnect(String tnsDescriptor)
at OracleInternal.ServiceObjects.OracleConnectionImpl.Connect(ConnectionString cs, Boolean bOpenEndUserSession, String instanceName)
at OracleInternal.ConnectionPool.PoolManager`3.CreateNewPR(Int32 reqCount, Boolean bForPoolPopulation, ConnectionString csWithDiffOrNewPwd, String instanceName)
at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword)
at Oracle.ManagedDataAccess.Client.OracleConnection.Open()
试试看,可能你的C盘也满了。
之后,restart for some oracle services using Task Manager 检查 Mikael Holmgren 的答案
【讨论】:
以上是关于OracleConnection.Open 抛出 ORA-12541 TNS no listener的主要内容,如果未能解决你的问题,请参考以下文章