C# OracleConnection.Open 抛出 ORA-12541 TNS no listener

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12571379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 23:44:59  来源:igfitidea点击:

OracleConnection.Open is throwing ORA-12541 TNS no listener

c#oracleoracle11gdatabase-connectionconnection-string

提问by RG-3

So I am connecting to an external server through C#. I just installed Oracle 11gclient on my machine from here: http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html(255MB one).

所以我通过 C# 连接到外部服务器。我刚刚从这里在我的机器上安装了Oracle 11g客户端:http: //www.oracle.com/technetwork/database/windows/downloads/index-090165.html(一个 255MB)。

After reading many blogs/questions I found this article to be useful:

在阅读了许多博客/问题后,我发现这篇文章很有用:

http://dbaspot.com/oracle-faq/444787-ora-12541-tns-no-listener.html

http://dbaspot.com/oracle-faq/444787-ora-12541-tns-no-listener.html

So is this correct? I cannot do anything. The DBA has to edit the LISTENER.ORAfile?

那么这是正确的吗?我什么都做不了。DBA 必须编辑LISTENER.ORA文件吗?

My tnsnames.oralooks like this:

我的tnsnames.ora看起来像这样:

  TestingConnect=
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = TestHostName.us.local)(PORT = 1523))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = TEST)
    )
  )

It is throwing me the err at:

它让我犯了错误:

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!!!

What should I do? I appreciate any comments. Thanks!

我该怎么办?我很欣赏任何评论。谢谢!

采纳答案by RG-3

Thanks for all your input. I changed my connection string and it worked. Here its what looks like:

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

 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;";
    }

回答by dkackman

You can do this a couple of ways: Using your TNSNames file the data source should specify the TNSHosts entry name (the bit before the first "=" from the tnsnames.ora), not the host name:

您可以通过以下几种方式执行此操作:使用 TNSNames 文件,数据源应指定 TNSHosts 条目名称(tnsnames.ora 中第一个“=”之前的位),而不是主机名:

connection.ConnectionString = "Data Source=TestingConnect;Persist Security Info=True;" + "User ID=tesName;Password=test"; 

Or you can put the entire TNS entry in the connection string like so:

或者您可以将整个 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";