10

所以我通过 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!!!

我该怎么办?我感谢任何评论。谢谢!

4

3 回答 3

9

您可以通过以下几种方式执行此操作:使用您的 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"; 
于 2012-09-24T19:22:25.547 回答
7

感谢您的输入。我改变了我的连接字符串,它工作。这是它的样子:

 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;";
    }
于 2012-09-25T00:33:27.877 回答
0

在我的情况下,当驱动器 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盘也满了。

之后,使用任务管理器重新启动一些 oracle 服务检查 Mikael Holmgren 的答案

于 2021-10-05T14:13:59.787 回答